I use Xcode4, and my program won't seem to open a text input file. I tried everything from renaming the file name to "sample.txt" and "sample" only, but it still doesn't work.
I also tried putting it in all directories.
It worked in windows Dev C++ BLood shed, but doesn't seem to work in Xcode4.
Please help, machine project is due soon.
P.S. Begginner programmer here, so please don't use too technical terms, I would appreciate a step by step. Thanks.
Nothing wrong in my code I'm sure, but here you go.
Heres my code:
I also tried putting it in all directories.
It worked in windows Dev C++ BLood shed, but doesn't seem to work in Xcode4.
Please help, machine project is due soon.
P.S. Begginner programmer here, so please don't use too technical terms, I would appreciate a step by step. Thanks.
Nothing wrong in my code I'm sure, but here you go.
Heres my code:
Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
char filename[40];
char ch;
FILE *fp;
fprintf(stdout, "Input filename: ");
fscanf(stdin, "%s", filename);
if ((fp = fopen(filename, "r")) == NULL)
{
fprintf(stderr, "ERROR: %s does not exist.\n", filename); exit(1);
}
while ((fscanf(fp, "%c", &ch)) == 1) fprintf(stdout, "%c", ch);
fclose(fp);
return 0; }
Last edited by a moderator: