I have file command.c:
#include <stdlib.h>
#include <stdio.h>
#define MAXLEN 1000
/* write_message: if argument != NULL, write argument to group, else open group in vim
* returns 0 on success
* returns -1 on failure
*/
int write_message(char *message, char *path, char *group) {
char *editor, sys_call[MAXLEN];
editor = "vim";
if (message == NULL) {
snprintf(sys_call, MAXLEN, "%s %s%s.txt", editor, path, group);
printf("sys_call = %s\n", sys_call);
/* return system(sys_call);*/
}
return 0;
}
when I compile with gcc -Wall -Werror -std=c89 -c command.c I get the error message:
command.c: In function ‘write_message’:
command.c:16:9: error: implicit declaration of function ‘snprintf’ [-Werror=implicit-function-declaration]
16 | snprintf(sys_call, MAXLEN, "%s %s%s.txt", editor, path, group);
| ^~~~~~~~
command.c:2:1: note: ‘snprintf’ is defined in header ‘<stdio.h>’; did you forget to ‘#include <stdio.h>’?
1 | #include <stdlib.h>
+++ |+#include <stdio.h>
cc1: all warnings being treated as errors
I can not use snprintf because it is not defined even though I have included stdio.