I'm trying to make a basic C program to read from a file, but for some reason when I run it with make Test1
and then ./Test1 test1.txt
I get "error: 's' may be used uninitialized in this function".
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char** argv) {
if (argc < 2) {
printf("error\n");
return 0;
}
FILE *fp = fopen(argv[1], "r");
if (fp == NULL) {
printf ("error\n");
return 0;
}
char * s;
int r = fscanf(fp, "%s", s);
while (r != EOF) {
printf("%s\n", s);
r = fscanf(fp, "%s", s);
}
return 0;
}