简体   繁体   中英

error using fgets()

Hi can someone help me with this error? The errors I'm getting are:

Building target: Programming Cpt220
/bin/sh: -c: line 0: syntax error near unexpected token `('
Invoking: MacOS X C++ Linker
/bin/sh: -c: line 0: `g++  -o "Programming Cpt220"  ./fgets()exampleFromTheNet.o   '
make: *** [Programming Cpt220] Error 2
g++  -o "Programming Cpt220"  ./fgets()exampleFromTheNet.o 

I'm not sure why ist is asking for g++ -o I'm using eclipse on Mac.

#include <stdio.h>
#include <stdlib.h>

#define  MAX_LEN  100

int main(void)
{
   FILE *stream;
   char line[MAX_LEN], *result;

   stream = fopen("myfile.dat","r");

   if ((result = fgets(line,MAX_LEN,stream)) != NULL)
       printf("The string is %s\n", result);

   if (fclose(stream))
       printf("fclose error\n");


}

Remove the () from the filename of your C file.

ie fgets()exampleFromTheNet.c -> fgetsExampleFromTheNet.c

() has a special meaning in bash and other shells. Hence it is recommended to avoid having any special characters in filenames.

看起来您的文件名中似乎有一个“()”,这正在杀死您正在运行的shell脚本。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM