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

Recommended Answers

All 2 Replies

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

file=fopen(adress,"a+");

Ah i see!

Thank you very much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.