我的c程序怎么老是弄不出来阿

Vim、Emacs配置和使用
w3484732
帖子: 36
注册时间: 2007-05-11 19:48
来自: 湖北襄樊

我的c程序怎么老是弄不出来阿

#1

帖子 w3484732 » 2008-03-10 20:17

我一直都不能完成最基本的C程序!
我想输入一个简单的C程序HELLO WORLD
是这样编译的:
#include <stdio.h>

int main()
{
printf("Hello, world!\n");
return 0;
}

存为并退出:hello.c
在终端输入:gcc -o hello.c vi.c回车
出现:
wangxuyuan@wangxuyuan-laptop:~$ gcc -o hello.c vi.c
gcc: vi.c:No such file or directory
gcc: 没有输入文件
wangxuyuan@wangxuyuan-laptop:~$

这是怎么回事阿,大家能看看我是那里出错了?
C程序我在很多地方找到的都不一样!这是怎么回事?
如:我在书上看到的:
#include<iostream>

int main()
{
std::cout<<"hello world!\n;
return 0;
}
urmysweety
帖子: 99
注册时间: 2006-06-09 9:37

#2

帖子 urmysweety » 2008-03-10 20:31

gcc -o aaa hello.c
这样看看
其中aaa是自己定义生成的可执行文件的名称
w3484732
帖子: 36
注册时间: 2007-05-11 19:48
来自: 湖北襄樊

#3

帖子 w3484732 » 2008-03-10 20:34

wangxuyuan@wangxuyuan-laptop:~$ gcc -o aaa hello.c
hello.c:1:19: 错误: stdio.h:No such file or directory
hello.c: 在函数 ‘main’ 中:
hello.c:5: 警告: 隐式声明与内建函数 ‘printf’ 不兼容
wangxuyuan@wangxuyuan-laptop:~$
不行!是不是我写的程序有问题?
urmysweety
帖子: 99
注册时间: 2006-06-09 9:37

#4

帖子 urmysweety » 2008-03-10 20:44

你安装了库没有?
dbzhang800
帖子: 3182
注册时间: 2006-03-10 15:10
来自: xi'an China
联系:

#5

帖子 dbzhang800 » 2008-03-10 20:47

w3484732 写了:wangxuyuan@wangxuyuan-laptop:~$ gcc -o aaa hello.c
hello.c:1:19: 错误: stdio.h:No such file or directory
hello.c: 在函数 ‘main’ 中:
hello.c:5: 警告: 隐式声明与内建函数 ‘printf’ 不兼容
wangxuyuan@wangxuyuan-laptop:~$
不行!是不是我写的程序有问题?

代码: 全选

sudo apt-get install build-essential
先装好编译环境。
w3484732
帖子: 36
注册时间: 2007-05-11 19:48
来自: 湖北襄樊

#6

帖子 w3484732 » 2008-03-10 21:03

哦!那我先去装!

现在出现了个问题!
我退出VIM后再使用:vim hello.c打开我编译的文件时出现:
E325: ATTENTION
Found a swap file by the name ".hello.c.swp"
owned by: wangxuyuan dated: Mon Mar 10 20:54:54 2008
file name: ~wangxuyuan/hello.c
modified: YES
user name: wangxuyuan host name: wangxuyuan-laptop
process ID: 10175
While opening file "hello.c"
dated: Mon Mar 10 20:12:36 2008

(1) Another program may be editing the same file.
If this is the case, be careful not to end up with two
different instances of the same file when making changes.
Quit, or continue with caution.

(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r hello.c"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file ".hello.c.swp"
to avoid this message.
"hello.c" 7L, 74C
Press ENTER or type command to continue


完后点个回车就好了,这是怎么回事?
dbzhang800
帖子: 3182
注册时间: 2006-03-10 15:10
来自: xi'an China
联系:

#7

帖子 dbzhang800 » 2008-03-10 21:24

两个可能原因你自己都贴出来了。

1 你用vim打开文件时,可能有一个vim已经打开了该文件

2 你上次用vim编辑该文件时vim崩溃了,比如 直接关掉终端,直接关机等导致vim被强制关掉
w3484732
帖子: 36
注册时间: 2007-05-11 19:48
来自: 湖北襄樊

#8

帖子 w3484732 » 2008-03-10 21:36

哦是这样的阿!谢谢受教了!
我现在按上面说的完成了HELLO WORLD的编译.但是生成的aaa程序不能运行,双击没有反应!
这是怎么回事?在终端里可以运行!
wangxuyuan@wangxuyuan-laptop:~$ ./aaa
Hello, world!
wangxuyuan@wangxuyuan-laptop:~$
这个没有问题!但是在图文界面上就不行了

[img]file:///home/wangxuyuan/Desktop/Screenshot.png[/img]

这是怎么回事阿?
附件
Screenshot.png
头像
Yizer
帖子: 297
注册时间: 2007-11-07 14:41
来自: 佳木斯
联系:

#9

帖子 Yizer » 2008-03-10 21:49

w3484732 写了:哦是这样的阿!谢谢受教了!
我现在按上面说的完成了HELLO WORLD的编译.但是生成的aaa程序不能运行,双击没有反应!
这是怎么回事?在终端里可以运行!
wangxuyuan@wangxuyuan-laptop:~$ ./aaa
Hello, world!
wangxuyuan@wangxuyuan-laptop:~$
这个没有问题!但是在图文界面上就不行了

[img]file:///home/wangxuyuan/Desktop/Screenshot.png[/img]

这是怎么回事阿?
你双击时已经运行了。。。。只是太快了一闪而过而已。。。。
Dell 1520
------------------------
Intel Core T7500
1G*2
120G
Nvidia 8600 GT
My BLOG
w3484732
帖子: 36
注册时间: 2007-05-11 19:48
来自: 湖北襄樊

#10

帖子 w3484732 » 2008-03-10 21:56

晕有什么办法让他慢点么?给他加个什么命令?
头像
zhihuasz
帖子: 665
注册时间: 2008-01-01 17:25
来自: 深圳
联系:

#11

帖子 zhihuasz » 2008-03-10 22:09

w3484732 写了:晕有什么办法让他慢点么?给他加个什么命令?
scanf()
w3484732
帖子: 36
注册时间: 2007-05-11 19:48
来自: 湖北襄樊

#12

帖子 w3484732 » 2008-03-12 18:05

现在又来了个问题:
我把编译好的程序做了改动,用GCC就编译不了了,怎么回事阿?
实际情况:
编译后能运行的:

#include <stdio.h>

int main()
{
printf("Hello, wo1111111111111111111111rld!\n");
return 0;
}

再改动后的:

#include <stdio.h>

int main()
{
printf("Hello, w1orld!\n");
return 0;
}

使用GCC命令:
第一个:
wangxuyuan@wangxuyuan-laptop:~$ gcc -o wang hello.c
wangxuyuan@wangxuyuan-laptop:~$
第二个:
123: file not recognized: File format not recognized
collect2: ld 返回 1
wangxuyuan@wangxuyuan-laptop:~$
第二个告诉我说: 文件形式不承认。这是怎么回事阿?
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

#13

帖子 BigSnake.NET » 2008-03-12 18:34

rm 掉之前的文件
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
w3484732
帖子: 36
注册时间: 2007-05-11 19:48
来自: 湖北襄樊

#14

帖子 w3484732 » 2008-03-12 18:49

把什么都RM后又出现了:
附件
那个321不是说的话题里的!
那个321不是说的话题里的!
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

#15

帖子 BigSnake.NET » 2008-03-12 19:09

你怎么不看输出信息呢, 没有输入文件
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
回复