⑴ c語言如何把一個字元串中的數值全提取出放在一個數組裡面
首先,C語言沒有字元串類型,但是字元數組或者字元指針可以表示字元串。 所以你可以把幾個字元串分別放到幾個不同數組: 例如: char str1[10] = "abcdefg";char str2[10] = "qwerty";注意,定義字元數組時可以使用=直接賦值,非定義階段,不能...
⑵ C語言 將用戶輸入的字元串中的所有數字提取出來
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
intmain()
{
intz=0;
intt,i;
int*p;
intm=0;
ints=0;
chara[10];//輸入一個字元串到a[6]
printf("請輸入一個字元串 ");
scanf("%s",a);//輸入字元串
for(i=0;i<10;i++)//計算a[6]中的數字個數
{
if(a[i]>='0'&&a[i]<='9')
m++;
}
if(m==0)
printf("字元串中沒有數字 ");
p=(int*)calloc(m,sizeof(int));//動態數組
for(i=0;i<10;i++)
{
if(a[i]>='0'&&a[i]<='9')
{
*(p+s)=a[i]-48;
s++;
}
}
//組成新的整數
for(t=0;t<m;t++)
{
z+=(*(p+t))*pow(10,m-(t+1));//組成新的整數
}
printf("新組成整數:%d ",z);
free(p);
}
kuo
(2)將字元串中的數字提取出來c語言擴展閱讀
C語言實現將字元串的數字提取為整數
#include<stdio.h>
intStringToInteger(char*p)
{
intvalue=0;
while(*p!='