Is it possible to name a file using a variable in c programming? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Is it possible to name a file using a variable in c programming?

The user should be able to name the file that would be created.

13th Feb 2020, 2:49 AM
Jergan Hector
Jergan Hector - avatar
6 Answers
+ 7
Yup. It is possible. See this turorial https://www.sololearn.com/learn/C/2952/
13th Feb 2020, 2:56 AM
Pedro H.J
Pedro H.J - avatar
+ 5
// Yes you can , fopen() will create new file if that file.txt is dose not exist FILE *fp; fp=fopen("file.txt","w");
13th Feb 2020, 2:56 AM
Sudarshan Rai
Sudarshan Rai - avatar
+ 3
I made this code using a variable. See this code. https://code.sololearn.com/cRLY3Pi661TF/?ref=app
13th Feb 2020, 3:01 AM
Pedro H.J
Pedro H.J - avatar
+ 2
LastSecond959 If try open the file without name it does not work.
13th Feb 2020, 2:27 PM
Pedro H.J
Pedro H.J - avatar
+ 1
Yes the filename can be a variable whose value is provided by the user.
13th Feb 2020, 4:26 AM
Sonic
Sonic - avatar
0
Pedro H.J So the input must be name.txt right? Is it valid if I just input the name of the file without .txt or .in etc?
13th Feb 2020, 1:39 PM
LastSecond959
LastSecond959 - avatar