0

Hello

Im new to C programming, im trying to learn how to create a textfile with whatever name the user of the program wants.

something like this, please ignore that this code wont work, its just so you might understand how i am thinking:

FILE *file;
  printf("name of the file: ");
  scanf("%s",adress);
  file=fopen("%s",adress,"a+");
  
  if(file==NULL){
    printf("File does not exist, creating file with desired filename");

So, im thiking to name the file to whatever the user inputs in a string, is this possible or should i consider some other way than string?

Thanks

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Fredszky
0

just remove the "%s" -- its not necessary because adress is already a string that contains the filename

file=fopen(adress,"a+");
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.