[英]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. 我不确定为什么ist要求g ++ -o我在Mac上使用eclipse。
#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. 从C文件的文件名中删除
()
。
ie fgets()exampleFromTheNet.c
-> fgetsExampleFromTheNet.c
即
fgets()exampleFromTheNet.c
> fgetsExampleFromTheNet.c
()
has a special meaning in bash
and other shells. ()
在bash
和其他shell中有特殊含义。 Hence it is recommended to avoid having any special characters in filenames. 因此,建议避免在文件名中包含任何特殊字符。
看起来您的文件名中似乎有一个“()”,这正在杀死您正在运行的shell脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.