c语言 strcpy的作用
摘要: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
阅读(10607)
推荐(0) 编辑
c 语言 字符串“空格”的应用
摘要: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
阅读(490)
推荐(0) 编辑
c语言 字符串数组的应用
摘要: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
阅读(272)
推荐(0) 编辑
c语言 灵活性的表现
摘要:1,同时完成赋值以及输出的功能 int a = 12; int b =3; printf("%d\n",a+=a-=a*a); printf("%d",a = b); //同时完成赋值和输出功能。2.逗号表达式的取值是最后一个表达式的值。3在printf函数中,如果想输出%号,应该使用俩个%号,如%%。4,格式说明符:d,ld,f,c,s,e,u,g,o,x5格式化scanf,如制定输入整型的位数。代码如下: long a =900000; int b,c; scanf("%3d%3d",&b,&c); printf(
阅读全文
posted @
2011-10-13 15:10
wtq
阅读(272)
推荐(0) 编辑
c 语言 转义字符 以及类型转换
摘要:1,\ddd表示八进制。应用:\101输出字母A,代码如下:char ch ='\101'; printf("%c",ch);2在c语言的强制类型转换时,得到的是一个所需类型的中间变量,原来变量的类型未发生变化,float f;int i;f=3.4;i = (int)f;printf("i= %d,f = %f",i,f);此句输出的是3和3.4,变量f仍然是3.43,在进行运算符进行结合时,如下代码int ii;ii=3;printf("-ii++=%d\n",-ii++);printf("ii=%d\n
阅读全文
posted @
2011-10-12 22:03
wtq
阅读(452)
推荐(0) 编辑
c语言 自定义strstr
摘要:char *strstr(char *p1,char *a){ char *p2,*p; for(;*p1!='\0';) { p2=p1; p=a; for(;*p!='\0';) { if(*p==*p2) { p++; p2++; } else { break; } } if(*p=='\0') { return p1; } p1++; } return 0;}
阅读全文
posted @
2011-10-12 16:08
wtq
阅读(414)
推荐(0) 编辑
c语言 strlower 将所有的字母转化为小写字母
摘要:char *strlower(char *p1){ char *p2; p2 = p1; for(;*p1!='\0';) { if(*p1<=90 && *p1>=65) { *p1 = *p1+32; } p1++; } return p2;}
阅读全文
posted @
2011-10-12 13:17
wtq
阅读(782)
推荐(0) 编辑
c语言 自定义strup将所有的字母转化为大写字母
摘要:char *strup(char *p1){ char *p2; p2 = p1; for(;*p1!='\0';) { if(*p1<=122 && *p1>=97) { *p1 = *p1-32; } p1++; } return p2;}
阅读全文
posted @
2011-10-12 13:15
wtq
阅读(331)
推荐(0) 编辑
c语言 自定义strlen
摘要:int strlen(char *p1){ int length; length=0; while(*p1++) length++; return length;}
阅读全文
posted @
2011-10-12 13:02
wtq
阅读(265)
推荐(0) 编辑
c语言 自定义strcopy
摘要:方法1; void strcopy(char *p1,char *p2){ for(;*p1!='\0';) { *p2++=*p1++; } *p2='\0'; }方法2:void strcopy(char *p1,char *p2){ for(;(*p2++=*p1++)!=0;); }方法3.void strcopy(char *p1,char *p2){ while(*p2++=*p1++); }
阅读全文
posted @
2011-10-12 12:59
wtq
阅读(409)
推荐(0) 编辑
c语言 自定义strcmp
摘要:代码如下:int strcmp(char *p1,char *p2){ for(;*p1!='\0';) { if(*p1>*p2 )) { return 1 ; } else if((*p1<*p2)) { return -1; } p1++; p2++; } return 0;}
阅读全文
posted @
2011-10-12 12:44
wtq
阅读(469)
推荐(0) 编辑
c 语言 存储字符串的方法
摘要:1,使用字符数组,代码如下:char name[]="wangtianqiao"; char *cPoint; cPoint = name ; printf("%s\n",name); printf("%c",name[4]); printf("%c",*(cPoint+4));2,使用字符指针,代码如下: char *cPoint="wangtianqiao"; printf("%s",cPoint);3,把字符串a赋值给字符串b,注意字符串都是以'\0'结
阅读全文
posted @
2011-10-11 23:44
wtq
阅读(3720)
推荐(0) 编辑
c语言 指针总结
摘要:指针变量为iPoint ,整型变量为i。执行赋值:iPoint = &i;1.&*iPoint 相当于变量iPoint;2.*&i 相当于变量i; 3,(*iPoint)++是使变量a的值加14,*iPoint++ 是先使用iPoint的值,再使iPoint指向下一个变量。 5.*++iPoint 是先使iPoint指向下一个变量,然后再取出下一个变量的值。 5.指针的一个很重要的特点是可以改变实参指针变量所指变量的值,这时指针是当做函数的参数来传递的。6.在c语言中数组名代表着首元素的地址。 7,指针变量与数组:iPoint+i等价于a+i 等价于&a[i]
阅读全文
posted @
2011-10-11 17:21
wtq
阅读(224)
推荐(0) 编辑
c语言 输出变量的地址,动态的观察内存的分配。
摘要:1,使用%x 来输出变量的地址View Code 1inti,j,k;2charch,ch1;3floatf1,f2;45printf("%x%x%x%x%x%x%x",&i,&j,&k,&ch1,&ch,&f1,&f2);6scanf("%d",&i);7printf("%d",i);8printf("%x",&i);2,观察指针变量地址的分配。经实验表明,指针变量的地址也和其他类型的变量地址分配类似,他们都处于同一块区域。如下代码:View
阅读全文
posted @
2011-10-11 12:22
wtq
阅读(1034)
推荐(0) 编辑
c语言 字符与整型之间的关系
摘要:1,字符可以当做整型进行自加自减。代码如下:char ch ; ch=100; printf("%c",ch); while(ch>0) { printf("%c___%d ",ch,ch); ch--; }2.字符型和整型可以互相赋值char ch ; int i; ch=100; ch+=1; printf("%c",ch); i = 'a'; i+=1;
阅读全文
posted @
2011-10-11 11:47
wtq
阅读(573)
推荐(0) 编辑