c语言问题

软件和网站开发以及相关技术探讨
回复
w3484732
帖子: 36
注册时间: 2007-05-11 19:48
来自: 湖北襄樊

c语言问题

#1

帖子 w3484732 » 2008-07-18 21:18

我按照书本编译了个程序请看:

/*Illustrates the moduls operatior.*/
/*Inpust a number of seconds,and converts to hours,*/
/*minyres,and seconds.*/

#include<stdio.h>

/*Dedine constants*/

#define SECS_PER_MIN 60
#define SECS_PER_HOUR 3600

unsigned seconds,minutes,hours,secs_left,mins_left;

int main(void)
{
/*Input the number of seconds*/

printf("Enter number of seconds (<6500):");
secanf("%d",&seconds);

hours=seconds/SECS_PER_HOUR;
minutes=seconds/SECS_PER_MIN;
mins_left=minutes%SECS_PER_MIN;
secs_left=seconds%SECS_PER_MIN;

printf("%u seconds is equal to ",seconds);
printf("%u h, %u m, and %u s\n",hours, mins_left, secs_left);

return 0;
}

最后编译不了了,显示:

wangxuyuan@wangxuyuan-laptop:~$ gcc seconds.c -o seconds
/tmp/ccXZfD3j.o: In function `main':
seconds.c:(.text+0x2d): undefined reference to `secanf'
collect2: ld 返回 1
wangxuyuan@wangxuyuan-laptop:~$
这是怎么回事阿,我输入的没有问题阿!
能请大家看看是怎么回事么!
头像
zszzd
帖子: 156
注册时间: 2007-12-12 22:54

#2

帖子 zszzd » 2008-07-18 23:14

把secanf
改成
scanf
w3484732
帖子: 36
注册时间: 2007-05-11 19:48
来自: 湖北襄樊

#3

帖子 w3484732 » 2008-07-21 20:33

这是怎么回事阿能给解释一下阿!

现在又出现了个相似的问题:
/*Demonstrtes the use of if statements*/

#include<stdio.h>

int x,y;

int main(void)
{
/*Input the two values to be tested*/

printf("\nInput an integer value fox x:");
scanf("%d",&x);
printf("\nInput an integer value fox y:");
scanf("%d",&y);

/*Test values and print result*/

if (x==y)
printf("x is equal tu y\n");

if (x>y)
peintf("x is greayer than y\n");

if (x<y)
printf("x is smaller than y\n");

return 0;
}

编译显示:
wangxuyuan@wangxuyuan-laptop:~$ gcc list0403.c -o list0403
/tmp/ccqqAf1K.o: In function `main':
list0403.c:(.text+0x83): undefined reference to `peintf'
collect2: ld 返回 1
wangxuyuan@wangxuyuan-laptop:~$
这个和我上 个问题比较相似,但是就楼上的:
把secanf
改成
scanf
这个说法我这回的编译直接就是scanf阿,怎么不能编译?
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

#4

帖子 BigSnake.NET » 2008-07-21 20:37

大哥你打字太多错误了, 键盘不舒服?
^_^ ~~~
要理解递归,首先要理解递归。

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

#5

帖子 w3484732 » 2008-07-21 20:41

不是把,那我 查查看看
w3484732
帖子: 36
注册时间: 2007-05-11 19:48
来自: 湖北襄樊

#6

帖子 w3484732 » 2008-07-21 20:43

那这个打错字编译器不能显示么?
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

#7

帖子 BigSnake.NET » 2008-07-21 20:45

wangxuyuan@wangxuyuan-laptop:~$ gcc list0403.c -o list0403
/tmp/ccqqAf1K.o: In function `main':
list0403.cSad.text+0x83): undefined reference to `peintf'
collect2: ld 返回 1

已经显示了
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
Stephen.Ada
帖子: 7
注册时间: 2008-07-16 13:05

#8

帖子 Stephen.Ada » 2008-07-21 21:17

可能在按r的时候按到了e吧。。。刚开始的时候是要多抄代码,不过有时候也容易犯这种错误,
lz加油吧,
回复