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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -