簡體   English   中英

使用fgets()時出錯

[英]error using fgets()

嗨,有人可以幫我解決這個錯誤嗎? 我得到的錯誤是:

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 

我不確定為什么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");


}

從C文件的文件名中刪除()

fgets()exampleFromTheNet.c > fgetsExampleFromTheNet.c

()bash和其他shell中有特殊含義。 因此,建議避免在文件名中包含任何特殊字符。

看起來您的文件名中似乎有一個“()”,這正在殺死您正在運行的shell腳本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM