明解C语言(入门篇)第十一章

1、练习11-1

#include<stdio.h>

int main(void)
{
	char *p="123";
	printf("p=\"%s\"\n",p);
	p="456"+1;
	printf("p=\"%s\"\n",p);	
    return 0;
}

在这里插入图片描述
2、练习11-2

#include<stdio.h>

int main(void)
{
	int i, n1, n2;
	char a[][5]={"LISP","C","Ada"};
	char *p[]={"Paul","X","MAC"};
    n1 = sizeof(a) / sizeof(a[0]);
    n2 = sizeof(p) / sizeof(p[0]);	
	for(i=0;i<n1;i++){
	printf("a[%d]=\"%s\"\n",i,a[i]);		
	}
	for(i=0;i<n2;i++){
	printf("a[%d]=\"%s\"\n",i,p[i]);		
	}	
    return 0;
}

3、练习11-3

#include<stdio.h>

char* str_copy(char *d, const char *s){
	char *t=d;
	while(*d++=*s++);
	return t;
}

int main(void)
{
	char str[128]="ABC";
	char tmp[128];

	printf("str=\"%s\"\n",str);		
	
	printf("复制的是:\n",tmp);
	printf("复制了");	
	scanf("%s",tmp);
	
	printf("str=\"%s\"\n",str_copy(str,tmp));	
    return 0;
}

4、练习11-4

#include<stdio.h>

void put_string(const char *s){
	while(*s){
		printf("%c",*s++);
	}
}

int main(void)
{
	char *str="ABC";	
	put_string(str);
    return 0;
}

5、练习11-5

#include<stdio.h>

int str_chnum(const char *s,int c){
	int num=0;
	while(*s){
		if(*s==c){
			num++;
		}
		*s++;
	}
	return num;
}

int main(void)
{
	char *str="ABccc";
	char ch='c';	
	printf("字符C的个数为%d\n",str_chnum(str,ch));
    return 0;
}

6、练习11-6

#include<stdio.h>

char *str_chr(const char *s,int c){
	char *p;
	while(*s){
		if(*s==c){
			p=s;
			break;
		}
		else{
			p=NULL;
		}
		*s++;
	}
	return p;
}

int main(void)
{
	char *str="ABccc";
	char ch='c';	
	printf("出现第一个字符C的指针为%d\n",*str_chr(str,ch));
    return 0;
}

7、练习11-7

#include<stdio.h>
#include<ctype.h>

void str_toupper(char *s){
	while(*s){
		*s=toupper(*s);
		*s++;
	}
}

void str_tolower(char *s){
	while(*s){
	*s=tolower(*s);
	*s++;
	}
}
int main(void)
{
	char str[128];
	printf("请输入字符串:");
	scanf("%s",str);
	
	str_toupper(str);
	printf("大写字母:%s\n",str);
	
	str_tolower(str);
	printf("小写字母:%s\n",str);
	return 0;
}

8、练习11-8

#include<stdio.h>
#include<string.h>

void del_digit(char *d,char *s){
	
	while(*s){
		if((*s>='a'&&*s<='z')||(*s>='A'&&*s<='Z')){
			*d=*s;
			*d++;
		}
		*s++;
	}
}

int main(void)
{
	char des[128];
	char src[128];
	printf("请输入字符串:");
	scanf("%s",src);
	
	del_digit(des,src);
	printf("删除字符串内的所有数字字符:%s\n",des);

	return 0;
}
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值