My simple program is read from the text file one word at a time.
example text file. (below)
N 101001 Circular Queue 11 1
N 123456 List Linker 11 5
N 666666 Pseudocode Gen 38 3
N 110010 Stack Stretcher 3 2
and simple codes including variables etc...
char function;
int number, init_stock, reorder;
char info[100];
FILE *fp;
if((fp = fopen("input.txt", "r")) == NULL)
{
printf("input open failed\n");
return 0;
}
while(!feof(fp))
{
fscanf(fp, "%c %d %[A-z, ] %d %d ", &function, &number, info, &init_stock, &reorder);
}
When a variable was changed within the ' while loop',
I expected to affect it the next loop as well.
so.. first, 'Circular Queue' was stored in 'info'.
Second, when 'List Linker' was stored in 'info' because second string is shorter than first string,
I thought that the info array had string like this 'List Linkerue'.
- info -- Circular Queue
- info -- List Linker+ue
But the info seemed to be reset every time, and I do not know why.