求c语言字符串程序设计源代码

来源:百度知道 编辑:UC知道 时间:2024/05/28 15:48:22
1.【编写程序】:从键盘上输入一行字符串(以回车结束),求出该字符串的长度,并分别统计其中字母、数字及其他字符的个数,并输出统计结果。
如:输入一行字符:f2k3T6&*8%5#9
字符串长度为:13,字母3个,数字6个,其它字符4个

2.【编写程序】:输入若干个字符串(以”stop”作为输入的最后一个字符串),求出每个字符串的长度,并输出最长的字符串。

(1)
#include<stdio.h>
#include<string.h>
void main()
{
char str[100];
int count1=0,count2=0,count3=0;
printf("input the string:\n");
scanf("%s",&str);
int size=strlen(str);
int i=0;
while(i<size)
{
if(str[i]>='a'&&str[i]<='z')
count1++;
else if(str[i]>='A'&&str[i]<='Z')
count1++;
else if(str[i]>='0'&&str[i]<='9')
count3++;
else count2++;
i++;
}
printf("长度:%d\n",size);
printf("字母 %d\n",count1);
printf("数字 %d\n",count3);
printf("其他字符 %d\n",count2);
}

(2)
#include<stdio.h>
#include<string.h>
void main()
{
char a[30][30];
char b[]="stop";
int i=0;
printf("i