maple412 发表于 2014-04-14 21:55

linux初学者的程序疑问

在cygwin下执行如下程序:
#include <unistd.h>
#include <stdlib.h>

int main()
{
        if ((write(1,"here is some data\n",18))!=18)
                write(2,"A write error has occurred on file descriptor 1\n",46);
                exit(0);
}

执行失败,报如下错误:
$ ./simple_write.c
./simple_write.c: line 4: syntax error near unexpected token `('
./simple_write.c: line 4: `int main()'

maple412 发表于 2014-04-14 21:57

程序怎么会将数字变成表情了呢? 重新贴一遍
#include <unistd.h>
#include <stdlib.h>

int main()
{
        if ((write(1,"here is some data\n",18))!=18)
                write(2,"A write error has occurred on file descriptor 1\n",46);
                exit(0);
}

qxhgd 发表于 2014-04-15 08:50

#include <unistd.h>
#include <stdlib.h>

int main()
{
    if ((write(1,"here is some data\n",1)!=1))
      write(2,"A write error has occurred on file descriptor 1\n",46);
    exit(0);
}
程序没错啊,可以出结果!

你检查下是否文件格式不对,或有中文字符!

MMMIX 发表于 2014-04-15 11:05

回复 2# maple412


    贴代码的时候用 括起来。

沉水之鱼 发表于 2014-04-15 19:21

..... 你这个。。。 你这个程序要编译 才能执行啊~
要用gcc编译成目标文件才能执行啊!
页: [1]
查看完整版本: linux初学者的程序疑问