2011年10月14日
摘要: 1,在c语言中,非字符数组初始化时,不能直接对字符数组进行赋值,可以使用strcpy对字符数组进行赋值。char a[]="this is my name ,and what's your name"; char b[]="my name is wang tiqn qiao"; char c[30]; strcpy(a,b);strcpy函数连'\0'都复制到目标数组。而strncpy函数不把'\0'复制到目标数组,有一种情况strncpy的效果跟strcpy的效果相同,就是把b数组的整个数组复制过去,包括' 阅读全文
posted @ 2011-10-14 16:28 wtq 阅读(10597) 评论(0) 推荐(0) 编辑
摘要: 1,在输入字符串时,空格作为字符串之间的分隔符char e[14]; scanf("%s",e); printf("%s\n",e);若输入how are you 时,则只把how的值赋给e变量。 2. 要输出内存地址时,可使用%u,% o,%x.如下: printf("%u,%o,%x",f,f,f);其中f是数组名。 阅读全文
posted @ 2011-10-14 15:56 wtq 阅读(479) 评论(0) 推荐(0) 编辑
摘要: 1,字符数组中的特殊字符‘、'\0'的作用char a[10] = {'i',' ','a','m',' ','c','h','i','n','a'}; char b[]="i am china"; printf("%d\n",strlen(a)); printf("%d\n",strlen(b)); printf("%s\n",a); pr 阅读全文
posted @ 2011-10-14 13:32 wtq 阅读(271) 评论(0) 推荐(0) 编辑