话不多说。。。。。:
#include<stdio.h>
#include<string.h>
#define DENSITY 62.4
int main()
{
float weight,volume;
int size,letters;
char name[5];
printf("HI!what's your weight in pounds?\n",name);
scanf("%f",&weight);
size=sizeof name;
letters=strlen(name);
volume=weight/DENSITY;
printf("well,%s,you volume is %2.2f cubic feet.\n",name,volume);
printf("Also,you first name has %d letters,\n",letters);
printf("and we have %d bytes to store it in.\n",size);
return 0;
}
其中的
size=sizeof name 中。。。sizeof 哪里来的。?? 前面找不到有关定义。。
还有。。
刚刚发现 有地方忘了输入。。(对比着教科书写的。。囧)。但是不耽搁输出。。
在输入的地方。填写数字或字母的话。。在
在输出中
HI!what's your weight in pounds?
www
well,諏噕德d傀b唙,you volume is 0.00 cubic feet.
Also,you first name has 21 letters,
and we have 5 bytes to store it in.
请按任意键继续. . .
well后面的东西是不是字符的随机??
那为什么在
Also,you first name has 21 letters,中 21 不变。。不管输入什么。。
当然。。也许是因为 size=sizeof name;,
好吧。。下面是正常的代码。。
#include<stdio.h>
#include<string.h>
#define DENSITY 62.4
int main()
{
float weight,volume;
int size,letters;
char name[40];
printf("HI!what's your first name?\n",name);
scanf("%s",name);
printf("%s,what's your weght in pounds?\n",name);
scanf("%f",&weight);
size=sizeof name;
letters=strlen(name);
volume=weight/DENSITY;
printf("well,%s,you volume is %2.2f cubic feet.\n",name,volume);
printf("Also,you first name has %d letters,\n",letters);
printf("and we have %d bytes to store it in.\n",size);
return 0;
}
在这里///。。。
char name[40];中,【a】的数字是a个字符的数组。。那么
这里面的40 不是固定的。。。 在书中写这个的原因///(也许是因为40 好看。。)
我发现当数字为1时(数字小),,输入的名字字母多时会以另一个样子输出。。。(乱码)。。
这是乱码 还是ASIIC码???
另外。。
在scanf("%s",name);中。。 name不需要&符号。。是不是因为 字符而非数字的关系。。
就这么多。。。代码太长////
本人又太菜。。。还请大家解释。。。。感激不尽