#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int log2 (int k) {
return (int)(log(k)/log(2));
}
void f2(char* a,char* b){
char temp = *a;
*a = *b;
*b = temp;
}
int main () {
int n = 123;
char str[50];
// itoa(n, str, 10);//需要 stdlib.h 头文件 功能等同于sprintf();
sprintf(str, "%d", n);//整形转字符串
puts(str);
int x;
x = atoi(str); //需要 stdlib.h 头文件 功能等同于sscanf();
sscanf(str, "%d", &x);//字符串转整形
printf("%d", x);
char p[5] = {"1234"};
char *q;
q = p;
for(int i=0;i<5&&p[i]!='\0';i++)
printf("%c",*q++);
int a = 4,b = 2;
const float t(1.0f/b);
printf("%d\n",a/b);
printf("%f\n",a*t);
char c1[] = "hello";
char* p1 = &c1[0];
int len = strlen(c1);
int i;
for(i = 0; i < len; i ++, p1 ++){
printf("%c", *p1);
}
return 0;
}
字符串运用
最新推荐文章于 2022-02-27 17:09:08 发布