I'm trying to create a file in C, but it's not working. The operating system is Linux.
#include <stdio.h>
void main (FILE *file) {
file = fopen("/home/Documentos/teste.odt", "w");
fprintf(file, "alo\n");
fclose(file);
}
I'm trying to create a file in C, but it's not working. The operating system is Linux.
#include <stdio.h>
void main (FILE *file) {
file = fopen("/home/Documentos/teste.odt", "w");
fprintf(file, "alo\n");
fclose(file);
}
Do this:
#include <stdio.h>
void main() {
FILE *file = fopen("/home/Documentos/teste.odt", "w");
fprintf(file, "alo\n");
fclose(file);
}
I placed GitHub for future reference .
You can not get a FILE
as a parameter in main()
. the main()
function can only receive strings (pointers to char
). this is not to say that a function can not receive a FILE
. Of course you can, but if you are to receive this type, you need to receive a die with this information. That is you have to create a FILE
somewhere and pass this structure created to the function that is prepared to receive this type of information. The problem with main()
is that its parameters come through the operating system (directly or indirectly) and in the OS it is not possible to create the type FILE
and pass, it only knows how to pass strings p>