简体   繁体   English

使用fgets()时出错

[英]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.

相关问题 如何在 fgets() 中故意触发错误? - How do I intentionally trigger an error in fgets()? 与fgets()函数的效率和使用&gt;&gt;运算符有关 - Relating efficiency of fgets() function and using >> operator 如何使用fgets获取整行 - How to get whole line using fgets 在Visual C ++中的fgets()上接收访问冲突错误 - Receiving access violation error on fgets() in visual c++ 结合使用cin.getline和fgets时防止缓冲区溢出 - Prevent buffer overflow when using cin.getline and fgets in conjugation 使用fgets作为非阻塞函数C ++ - using fgets as non-blocking function c++ 使用&#39;fgets&#39;读取char只是在运行时跳过 - Using 'fgets' to read in a char is just skipping when running “错误&#39;SetWindowTextA&#39;:不是&#39;CStatic&#39;的成员,并且char * fgets(char *,int,FILE *):无法将参数1从&#39;TCHAR&#39;转换为&#39;char *&#39; - "Error 'SetWindowTextA': is not a member of 'CStatic' and char *fgets(char*, int, FILE*): can not convert argument 1 from 'TCHAR' to 'char*' 使用C ++,当行中的最后一个整数为0时,如何检测到fgets整数字符串的末尾? - How to detect you've reached the end of a fgets string of integers, when 0 is the last integer in the line, using c++? 在 ICU4C ustdio.h 中使用 u_fgets 时如何测试新行的长度? - How to test the length of a new line when using u_fgets in ICU4C ustdio.h?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM