We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,415 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

why it reads all config file parameters as 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.

3
Contributors
4
Replies
14 Hours
Discussion Span
1 Year Ago
Last Updated
5
Views
placebo1
Newbie Poster
3 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

VernonDozier
Posting Expert
5,675 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 738
Skill Endorsements: 18

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

placebo1
Newbie Poster
3 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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?

v3ga
Junior Poster in Training
95 posts since Oct 2011
Reputation Points: 14
Solved Threads: 5
Skill Endorsements: 0

thank you all, i have fixed it.

it is the overloading issue.

placebo1
Newbie Poster
3 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.3197 seconds using 2.71MB