I need to output the arguments passed to a program into a file. Every time I do it, it outputs (null)
at the end of every line.
This is what I have got:
#include <stdio.h>int main(int argc, char *argv[]) { FILE *file = fopen("file.txt", "a+"); for (int i = 1; i <= argc; i++) { fprintf(file, " %s", argv[i]); } fputs("", file); // add newline at the end fclose(file);}
When I read the file with cat
I can see (null)
at the end of lines. Example:
asd def (null) second test (null)