指针----字符串

字符串
字符数组
1.使用字符串初始化字符数组
char ch[]=“hello world”;
scanf("%s",ch);printf("%s",ch);
2.字符串处理函数
gets(ch);


指针变量指向字符串
char *str=“hello”//使用字符串常量对字符指针进行初始化
str=str+2;
str=“world”
等价于
char *str=“hello”;
str=“hello”;
char ch[]=“hello”;
char ch[10];
ch=“hello”//错误
char *str=ch;
字符串在c内存中都是以数组的形式存放
char *mystract(char ch1[],char *ch2)
{int i,j;
for(i=0;;i++)
{if(ch1[i]==’\0’)
break;
}

for(j=0;;j++)
{if(ch2[j]==’\0’)
break;
}
for(y=0,x=i;y<=j;x++,y++)
ch1[x]=ch2[y];
return ch1;
}

char *mystract(char *ch1,char ch2)
{
int i,j;
for(i=0;;i++)
{if(
(ch1+i)==’\0’)
break;
}

for(j=0;;j++)
{if(*(ch2+j)==’\0’)
break;
}
for(y=0,x=i;y<=j;x++,y++)
(ch1+x)=(ch2+y);
return ch1;
}
案例,字符串连接函数
char *mystract(char *ch1,char *ch2)
{ char p=ch1;
while(ch1!=’\0’)
ch1++;
while(*ch2!=’\0’)
{*ch1=*ch2;
ch1++;ch2++;
}
ch1=’\0’;return p;
}
#define A 5
#define B 6
#define C A+B
int x=2
C ============》x=2
A+B ==== 》x=2
5+6

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值