Hello,
I've been practicing writing small programs, but now I'm finding that whenever I try to run it, it runs, but half-way into the program Windows displays the (myprogram has encountered a problem and has to close).
Here's my code for reference:
I know there are at least two problems here, but the compiler reports them as 'warnings' as opposed to errors. One is surely that fgetc can't pass the character to a point within an array, but I can't find a function that can do that, unless I use fgets, but then I'm not sure how to move from one line to another in the file!Code:#include <stdio.h> #include <string.h> int main() { char *filename; printf("Please enter the filename"); scanf("%c", &filename); fopen(filename,"r"); char filetext[1024]; int i = 0; for(i = 0; i <= 1024; i++) { filetext[i] = fgetc(filename); tolower(filetext[i]); } printf("%s",filetext[i]); if(i = " ") { printf("\n"); } }
Also, I think my tolower may be faulty. I can't find that function in the C reference guide, but then again I can't find a function to convert characters to lowercase in the printf operator list either.
The file being referenced is simply a notepad text file with the text "This is an example file." (without the "'s).
If anyone can lend a hand with this I'd be grateful.
Thanks.
Hussein.



LinkBack URL
About LinkBacks



