Error creating file in C

3

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);
}
    
asked by anonymous 18.11.2014 / 00:08

1 answer

6

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>     

18.11.2014 / 00:17