反問你一個問題:如果你輸入的是int型,那麼怎麼會有字元型的出來呢?可以參考一下別人寫的程式碼:
#include<stdio.h>#include<string.h>void main(){ char array[100]; void fun(char*); gets(array); fun(array);}void fun(char array[100]){ int sum=0,i; for(i=0;i<strlen(array);i++) { sum*=16; if("0"<=array[i]&&array[i]<="9") sum+=array[i]-"0"; if("a"<=array[i]&&array[i]<="z") sum+=array[i]-"a"+10; if("A"<=array[i]&&array[i]<="Z") sum+=array[i]-"A"+10; } printf("%d",sum);}
反問你一個問題:如果你輸入的是int型,那麼怎麼會有字元型的出來呢?可以參考一下別人寫的程式碼:
#include<stdio.h>#include<string.h>void main(){ char array[100]; void fun(char*); gets(array); fun(array);}void fun(char array[100]){ int sum=0,i; for(i=0;i<strlen(array);i++) { sum*=16; if("0"<=array[i]&&array[i]<="9") sum+=array[i]-"0"; if("a"<=array[i]&&array[i]<="z") sum+=array[i]-"a"+10; if("A"<=array[i]&&array[i]<="Z") sum+=array[i]-"A"+10; } printf("%d",sum);}