//字符转换
#include <stdio.h>
#define MAXN 10
int main()
{
char str[MAXN];
int i=0,number=0;
while((str[i]=getchar())!='\n'){
i++;
}
str[i]='\0';
for(i=0;str[i]!=0;i++){
if(str[i]>='0' && str[i]<='9'){
number=number*10+str[i]-'0';
}
}
printf("%d",number);
return 0;
}
//将十六进制字符串转换为十进制非负整数
#include <stdio.h>
#include <math.h>
#define MAXN 80
int main()
{
char str[MAXN];
int i=0,number=0;
while((str[i]=getchar())!='#'){
i++;
}
str[i]='\0';
printf("Enter useful string:");
for(i=0;str[i]!='\0';i++){
if((str[i]>='0' && str[i]<='9') || (str[i]>='A' && str[i]<='F') || (str[i]>='a' && str[i]<='f')){
putchar(str[i]);
}
}
str[i]='\0';
printf("\n");
for(i=0;str[i]!='\0';i++){
if(str[i]>='0' && str[i]<='9'){
number=number*16+str[i]-'0';
}
else if(str[i]>='A' && str[i]<='F'){
number=number*16+str[i]-'A'+10;
}
else if(str[i]>='a' && str[i]<='f'){
number=number*10+str[i]-'a'+10;
}
}
printf("number=%d",number);
printf("\n");
return 0;
}
//查找指定字符
#include <stdio.h>
#define MAXN 80
int main()
{
int i,flag;
char ch,str[MAXN];
i=0;
while((str[i]=getchar())!='\n'){
i++;
}
str[i]='\0';
printf("Enter a ch:");
scanf("%c",&ch);
flag=0;
for(i=0;str[i]!='\0';i++){
if(str[i]==ch){
flag=1;
break;
}
}
if(flag==1){
putchar(str[i]);
printf(" ");
printf("i=%d\n",i);
}
else{
printf("Not Found\n");
}
return 0;
}