At some point in my code, I want to read a name for a file that I will be creating (and/or editing) and I've come up with the following:
FILE *fp;
char filename[15];
fgets(filename, 15, stdin);
fp = fopen(filename, "a");
fprintf(fp, "some stuff goes here");
fclose(fp);
Even though that does compile and run, it does not create (or open, if I manually create it) the file specified by filename
.
What would you suggest?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…