text - C file not reading properly -
when run following command in command terminal: gcc practice.c temp.txt
i following error:
/usr/local/binutils/2.21/bin/ld:temp.txt: file format not recognized; treating linker script /usr/local/binutils/2.21/bin/ld:temp.txt:1: syntax error collect2: ld returned 1 exit status here c code:
#include <stdio.h> #include <string.h> #include <stdlib.h> #define max_len 1024 int main(int argc, char **argv) { file *file; char line[max_len]; float value = 0; file = fopen(argv[1], "r"); while (fgets(line, max_len, file) != null) { sscanf(line, "%f", &value); printf("%f\n", value); } fclose(file); return 0; } basically trying read numbers in file , print them out. simple.
for example, temp.txt like:
10 26 27 52 242
(these numbers should in column)
and forth.
use gcc compile executable, , run executable on input file afterwards. error b/c gcc trying compile test.txt c source code.
so:
gcc practice.c -o practice ./practice test.txt
Comments
Post a Comment