就是定义一个函数,分别存放输出数字,字母,其他,这个函数怎么写啊
/*输入一串字符,然后分别存放输出数字,字母,其他*/
#include<stdio.h>
#define N 80
int main(void)
{
void myString(char *str,char *ch,char *num,char *other);
char str[N],ch[N],num[N],other[N];
printf("输入一个字符串: ");
gets(str);
myString(str,ch,num,other);
printf("字母: %s\n数字: %s\n其它: %s\n",ch,num,other);
return 0;
}
void myString(char *str,char *ch,char *num,char *other)
{
int i,j,k,m;
for(i=j=k=m=0;str[i]!='\0';i++)
if((str[i]|32)>='a'&&(str[i]|32)<='z')
ch[j++]=str[i];
else if(str[i]>='0'&&str[i]<='9')
num[k++]=str[i];
else
other[m++]=str[i];
ch[j]=num[k]=other[m]='\0';
return;
}
#include<stdio.h>
#define N 80
int main(void)
{
void myString(char *str,char *ch,char *num,char *other);
char str[N],ch[N],num[N],other[N];
printf("输入一个字符串: ");
gets(str);
myString(str,ch,num,other);
printf("字母: %s\n数字: %s\n其它: %s\n",ch,num,other);
return 0;
}
void myString(char *str,char *ch,char *num,char *other)
{
int i,j,k,m;
for(i=j=k=m=0;str[i]!='\0';i++)
if((str[i]|32)>='a'&&(str[i]|32)<='z')
ch[j++]=str[i];
else if(str[i]>='0'&&str[i]<='9')
num[k++]=str[i];
else
other[m++]=str[i];
ch[j]=num[k]=other[m]='\0';
return;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答 推荐于2017-12-16
void output_char(char * s)
{
if (s == NULL)
return;
int i = 0;
// 数字
for(i = 0; i < strlen(s); i++)
{
if (isdigit(s[i]))
printf("%c", s[i]);
}
printf("\n");
// 字母
for(i = 0; i < strlen(s); i++)
{
if (isalpha(s[i]))
printf("%c", s[i]);
}
printf("\n");
// 其他
for(i = 0; i < strlen(s); i++)
{
if (!(isalpha(s[i]) || isdigit(s[i])))
printf("%c", s[i]);
}
printf("\n");
}
头文件需要ctype.h本回答被网友采纳
{
if (s == NULL)
return;
int i = 0;
// 数字
for(i = 0; i < strlen(s); i++)
{
if (isdigit(s[i]))
printf("%c", s[i]);
}
printf("\n");
// 字母
for(i = 0; i < strlen(s); i++)
{
if (isalpha(s[i]))
printf("%c", s[i]);
}
printf("\n");
// 其他
for(i = 0; i < strlen(s); i++)
{
if (!(isalpha(s[i]) || isdigit(s[i])))
printf("%c", s[i]);
}
printf("\n");
}
头文件需要ctype.h本回答被网友采纳
第2个回答 2013-11-27
你可以判断一下(提示:假如是‘a’-‘z’的字母,放在一个字符串里,然后输出。然后有判断其他类的,数字或者汉字。)
你可以先想一下怎么写代码。不会的话可以追问我,学习进步。
你可以先想一下怎么写代码。不会的话可以追问我,学习进步。
第3个回答 2013-11-27
#include <stdio.h>
#include <string.h>
#define N 10 //可通过改变N 的值来改变输入字符串的长度
char a[30];
int i;
void main()
{
void Reverse(); //函数声明
printf("请输入字符串:");
scanf("%s",&a[i]);
printf("反转后的字符串:");
Reverse(); //函数调用
}
void Reverse() //函数定义
{
for(i=N;i>=0;i--)
printf("%c ",a[i]);
printf("\n");
}
#include <string.h>
#define N 10 //可通过改变N 的值来改变输入字符串的长度
char a[30];
int i;
void main()
{
void Reverse(); //函数声明
printf("请输入字符串:");
scanf("%s",&a[i]);
printf("反转后的字符串:");
Reverse(); //函数调用
}
void Reverse() //函数定义
{
for(i=N;i>=0;i--)
printf("%c ",a[i]);
printf("\n");
}
第4个回答 2013-11-27
void Test(const char* pSrc,int* pInt,char* pLetter,char* pOther);