1,105,546 Community Members

why it reads all config file parameters as 0

Member Avatar
placebo1
Newbie Poster
3 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

i want to read parameters from a file. but the program reads all parameters as if they are zero.any help?

here is the code

typedef unsigned long int WORD;
unsigned long int parameters[2]; 
WORD pt1[2];
void readConfig() 
{ char a[3];
   
    FILE *p; 


    p = fopen("config.data", "r"); 
    if (p) //we are reading 
    { 
      
        while(!feof(p)) 
        { 
        fscanf(p, "%s %lu", a, &parameters[0]);

parameters[0]=pt1[0];
  fscanf(p, "%s %lu", a, &parameters[1]);
parameters[1]=pt1[1];


    } 
  
    } 
    else  //we have an error, could not read 
    { 
        printf("Config file could not be read.\n"); //give warning 
    } 
    fclose(p); 
}

void main()

{ WORD i, j, k, pt2[2], ct[2] = {0,0};

unsigned char key[b];

readConfig();

printf("\n plain text %lu %lu \n", parameters[0], parameters[1]);

the program print the parameters as 0.

thanks in advance.

Member Avatar
VernonDozier
Posting Expert
5,632 posts since Jan 2008
Reputation Points: 2,218 [?]
Q&As Helped to Solve: 768 [?]
Skill Endorsements: 26 [?]
Featured
 
0
 

Lines 17 to 21...

fscanf(p, "%s %lu", a, &parameters[0]); // line 17
parameters[0]=pt1[0]; // line 19
fscanf(p, "%s %lu", a, &parameters[1]); // line 20
parameters[1]=pt1[1]; // line 21

Seems like whatever values are read from the file on 17 and 20 are immediately overwritten on lines 19 and 21 with ptr1[] values.

Member Avatar
placebo1
Newbie Poster
3 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

then what is your offer to read parameters properly and then assign them pt1[]?

Member Avatar
v3ga
Junior Poster in Training
95 posts since Oct 2011
Reputation Points: 4 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 0 [?]
 
0
 

What is the point of reading parameters[0] from file if u are replacing it with pt[1] later. Maybe what u mean is pt1[0]=parameters[0]? What are u using pt1[] (and pt2[],ct[],i,j,k) for anyway? can you post the full code?

Member Avatar
placebo1
Newbie Poster
3 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

thank you all, i have fixed it.

it is the overloading issue.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: