第六讲 C语言字符与字符串.ppt

第六讲 C语言字符与字符串

前导程序 #includestdio.h #includestring.h #define DENSITY 62.4 int main(void) { float weight,volume; int size,letters; char name[40]; printf(Hi!Whats your first name?\n); scanf(%s,name); printf(%s,Whats your weight in pounds?\n,name); scanf(%f,weight); size=sizeof name; letters=strlen(name); volume=weight/DENSITY; printf(Well,%s,your volume is %2.2f cubic feet.\n,name,volume); printf(Also,your first name has %d letters.\n,letters); printf(And we have %d bytes to store it in.\n,size); return 0; } 程序说明 它使用一个数组(array)来存放一个字符串。这里,某人的名字被读进这个数组中。该数组是内存中一串连续的40个字节,其中每个字节都是可以存放一个字符值。 它使用%

文档评论(0)

1亿VIP精品文档

相关文档