View Single Post
Go4Expert Member
11Mar2012,12:32  
Chong's Avatar
Quote:
Originally Posted by madhugupta View Post
Code:
#include <stdio.h>
#include <string.h>
 
struct inside {
        int field ;
};
 
struct initialdata {
        int timeout_t3_init;
        char eirp;
        int bsid[6];
        int priority[3][2];
        struct inside neighbor[2];
};
 
int main()
{
        struct initialdata ptr[2];
 
        ptr [0].timeout_t3_init =10;
 
        strcpy(ptr[0].eirp, "hello");
        ptr[0].bs_id[0]=1;
        ??
 
 
        FILE *fw,*fr;
 
        if ((fw=fopen("test.txt","rw"))==NULL){
                printf("File open for reading or writing failed\n");
                return -1;
        }
 
        fwrite(ptr,sizeof(struct initialdata),1,fw);
 
        fseek(fw,0,SEEK_SET);
        fread(ptr,sizeof(struct initialdata),1,fw);
 
 
 
        fclose(fw);
}
My intention is when i will open the test.txt file i need to see the parameter and coresponding value written in the txt file.

Hi M
there is a way to ouput into a text file and you can see parameters and valuesin the text file. use sscanf() and its opposite sprintf(). Getline(file,string) where string gets broken to fields with sscanf(line,"%s %d %d",&field1,&field2,&fields) and sprintf(line..) does exatly the opposite. outfile.write(line,strlen(line)) will do the work.

Best regards
Chong