heyas, i am having some trouble with understanding how i can overcome a problem. Currently, i have a file named 'woop.txt' , stored in the c:\. The contents of the file is 'hello'. I wish to store this contents as an array, named 'word'. The following code is what i wrote to gather the file contents and print it on the screen, this code compiles successfully and has no problems.
int main()
{
FILE *fp;
int c;
fp = fopen("woop.txt", "r");
while((c = getc(fp)) !=EOF)
putchar(c);
fclose(fp);
getch();
}
Now, if i have:
char word[5];
definied, in order to store the contents of each letter in the array, i am required to have a for loop (could be wrong! :P)
I already have a while loop running, however, and if i have
while((c = getc(fp)) !=EOF)
fscanf("%c", &word[]);
it generates an error. my code for the initial output of the file works with 'c' storing the contents of each individual character, i want to store each one of those characters in word[].
the only experience i have with such storing would be to have a for loop as follows:
for(x=0;x<5;x++)
scanf("%c", word[x]);
this, mixed with my original code will create problems, however, due to the embeded loops of a while>for:
while((c = getc(fp)) !=EOF)
for(x=0;x<5;x++)
fscanf("%c", word[x]);
this code is obviously not going to work.
please give me any ideas or help
thanks in advance
-twans