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.

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.

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

Member Avatar for v3ga

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?

thank you all, i have fixed it.

it is the overloading issue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.