㈠ c语言如何取一串字符串中的某个字符
C中的字符串就是一个字符数组。
如:
char s[10]="wo shi SB";
char c;
取最左边的字符,就是c=s[0];
㈡ C语言提取字符串中的所有数字
#include<stdio.h>
int
main()
{
char
str[1000];//保存读取到的字符串
long
sum=0,data[1000];
int
i=0,top=0;
printf("输入字符串:\n");
scanf("%s",str);
while(str[i]!='\0')//未到字符串末尾
{
if(str[i]>='0'&&str[i]<='9')//如果是数字
sum=sum*10+(str[i]-'0');//连续数字转换为数.
else
if(sum!=0)//保存这个数
{
data[top++]=sum;
sum=0;
}
i++;
}
if(sum!=0)//判断最后一个字符是否是数
data[top++]=sum;
printf("字符串中的数字是:\n");
i=0;
while(i<top)
{
printf("%ld",data[i]);
if(i<top-1)//不打印最后一个逗号
printf(",");
i++;
}
printf("\n");
system("pause");
return
0;
}
㈢ C语言中怎么查找字符串数组中的某个字符
程序有误,修改如下:
#include <stdio.h>
#include <string.h>
void main(){
char sh[20];
gets(sh);
for(int i=0;i<20;i++)
{
if(sh[i]='@')
{
printf("判断出有字符@ ");
break;
}
if(sh[i]='