I am new to the C/C++
My Program:
int main(int argc, _TCHAR* argv[])
{
//Declarations
FILE *fp;
char line[1000];
char *CheckPoint[3000];
//Opening a file and reading
fp = fopen("C:\\config.txt","rt");
while(fgets(line, 1000, fp) != NULL)
{
char datatext[1000];
sscanf (line, "%s", &datatext);
printf ("%s\n", datatext);
CheckPoint[i] = datatext;
}
//Closing File
fclose(fp);
return 0;
}
//Config.txt Data
10
20
30
40
My Question:
I am able to read the data from the file from the above loop of reading the file
but when i add it to the array the value incrementing the array and assiging it, the values gets changed
first time from the txt file i get 10 and i add to CheckPoint[i] = datatext; where initially i =0, the next loop when the value for the datatext = 20 the initial value get to 20 and also inserts 20 in the second place
Where am i going wrong
Please help me