//記憶字符串的函數
//1.strcpy賦值函數的用法;
/*char a[50]="hello world";
char b[50];
strcpy(b,a);
printf("%s",b);*/
//2.strcmp比較函數
/*char *a="hello world";
char *b="world hello";
printf("%d",strcmp(a,b)); */
//3.strcat拼接函數
/*char a[12]="hello world";
char b[6]=" dear";
strcat(a,b);
printf("%s",a);*/
//4.sscanf 字符整數轉換爲 整形整數
/* char a[6]="12345";
int b=0;
//函數方法:
// sscanf(a,"%d",&b);
//普通方法
int len = strlen(a);
for(int i=0;i<len;i++){
b=10*b+(a[i]-'0');
}
//atoi array to int 即字符串數組轉爲整形
b = atoi(a);
printf("%d",b);*/
//5.整形整數轉化爲字符整數 sprintf itoa
char a[6];
int b= 12345;
//字符數組a以整形的方式接收整形數字b
//sprintf(a,"%d",b);
//itoa函數的應用
itoa(b,a,10);
printf("%s",a);
c語言字符串簡單函數簡單應用
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.