c - fopen doesn't work, program crashes -
i'm trying open file fopen, , don't see what's going wrong. file in same directory main.c file. i've tried using full directory same results. help
int main() { const char file[2000]; int numwords = 0; scanf("%s", file); //printf("good"); printf("%s", &file); file *f; f = fopen(&file, "r"); if(f == null) { printf("cant open"); printf("\n%s", file); exit(2); } }
you need change
printf("%s", &file);
and
f = fopen(&file, "r");
to
printf("%s", file);
and
f = fopen(file, "r");
please follow man pages fopen()
, printf()
, enable compiler warnings.
Comments
Post a Comment