First, add this to the top:
Code:
#include <unistd.h>
Try compiling the program again, you'll get an error.
I think
close does not do what you think it's suppose to do. But I'll get back to that in a second... Your hello.c is empty when you compile it (try putting
system("cat hello.c") right before the other call to system), so there is no main function defined in it (this is because you didn't actually close the file). _start is actually the entry point in an elf executable, the standard C library actually implements this, and does some set up/clean up before/after calling main. If it doesn't exist, then there will be an undefined reference to main in the C runtime library's _start function. Back to the actual problem;
fclose is what you are looking for, and it takes a FILE pointer as an argument.
Code:
#include <stdio.h>
#include <string.h>
int main(void)
{
FILE* f_write;
char buf[1001];
f_write = fopen("hello.c", "w");
strcpy(buf, "#include <stdio.h>\n\nint main(void)\n{\n printf(\"Hello world!\\n\");\n return 0;\n}\n");
// buf = "#include <stdio.h>\n\nint main(void)\n{\n printf(\"Hello world!\";\n return 0;\n}";
fputs(buf, f_write);
fclose(f_write);
system("gcc -o hello hello.c");
return 0;
}