Opening file from variable(C)
https://code.sololearn.com/c2kD6uHq15kU/#c I have to open 26 files based on the input of the first file: the first file is series of 3 letters strings like ABC DEF etc. i have to open the files ABC.txt, DEF.txt... and im trying to do it with sprintf but it gives me an output i dont understand.
7/3/2020 5:33:54 PMGuido Parlatore
5 AnswersNew Answer
fopen does not work on sololearn. The playground is a remote server and cannot find the files on your computer. fgets does not work because is empty sommario
There are several problems: * The char pointers are uninitialized. * The call to fgets would return only 2 bytes, not 3. * Files are not getting closed Solutions: The char pointers need to be char arrays so that there is memory available to store the strings. char*xyz; //should be: char xyz; char*ilfile; //should be: char ilfile; In the call to fgets() the second argument (parameter n) should be changed from 3 to 4 in order to read 3 bytes. Calling fgets() reads n-1 bytes from the file and then it always adds a null as the nth byte. Remember to close each file that you open. You should have fclose(aprixyz); within the while loop.
I'm working on my computer, i just posted the code here to show it
And sommario is the txt file that i described in the description
Ok. Was not aware of that