《C语言入门经典》Ivor Horton第十章练习题1

//习题 10.1 编写一个程序,读入,存储以及输出下列5种类型的字符串,
//每个字符串占一行,字符串间不能有空格。
//	类型1:一串小写字母,后面跟一数字(如number1)
//	类型2:两个字单词,每个单词的第一个字母大写,单词间用-分隔(如Seven-Up)
//	类型3:小数(如7.35)
//	类型4:一串大小写字母及空格(如Oliver Hardy)
//	类型5:一除了空格及数字外的任何字符串(如floating-point)
//	以下是这五种字符串类型的例子,要分开读入这些字符串:
//	babylon5John-BOy3.14159STan Laurel'winner!'
#include<stdio.h>
#include<stdbool.h>
#define len 80
int main(void)
{	
	bool k=true;
	char word1[len]="\0";
	char word2[len]="\0";
	char word3[len]="\0";
	char word4[len]="\0";
	char word5[len]="\0";
	char temp1[len], temp2[len], temp3[len],temp4[len]
		,temp5[len], temp6[len], temp7[len], temp8[len]
		,temp9[len], temp10[len]="\0";
	
	
	while(k)
	{
		printf("\nplease enter the five strings");
		if(10!=scanf_s("%[a-z]%1[0-9]%1[A-Z]%[a-zA-Z]"
		"%[-]%1[A-Z]%[a-zA-Z]%[0-9.-]%[a-zA-Z ]%[^ 0-9\n]", temp1,len,temp2,len,temp3,len,
			temp4,len,temp5,len,temp6,len,temp7,
			len,temp8,len,temp9,len,temp10,len))
		{
			printf("\nerror enter");
			fflush(stdin);
		}
		else
		{
			printf("sssss");
			strcat_s(word1,len,temp1);
			strcat_s(word1,len,temp2);
			strcat_s(word2,len,temp3);
			strcat_s(word2,len,temp4);
			strcat_s(word2,len,temp5);
			strcat_s(word2,len,temp6);
			strcat_s(word2,len,temp7);
			strcat_s(word3,len,temp8);
			strcat_s(word4,len,temp9);
			strcat_s(word5,len,temp10);
			k=false;
		}
	}
	printf_s("\n%s\n%s\n%s\n%s\n%s",word1,word2,word3,word4,word5);
	return 0;

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值