Greetings all, this board has been a great help so far, and i feel kind of sheepish asking this because I've seen so many post conserning it, but none of the solotions have worked for me.
Anyway I thought was going to be the easiest part of my program: opening a file which the user specifies... i've reviewed the tutorials and past posts and come up with this:
It simpy isnt working for reasons unknown to me (I've also tried the method using BUFSIZ, but still not having any luck); any advice would be appreciated!Code:#include <stdio.h> #include <stdlib.h> main() { FILE *fp; char filename[40]; fgets(filename,40,stdin); if ( ( fp=fopen(filename, "a+" ) ) != NULL ) { fprintf(fp, "Testing...\n"); fclose(fp); } else printf("Could not open the file: %s", filename); }
Thanks