Start New Discussion within our Software Development Community

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("", "r"); 
    if (p) //we are reading 
        fscanf(p, "%s %lu", a, &parameters[0]);

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

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

void main()

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

unsigned char key[b];


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[]?

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?

This article has been dead for over six months. Start a new discussion instead.