scanf()所在头文件:stdio.h语法:scanf(“格式控制字符串”,变量地址列表);接受字符串时:scanf(“%s”,字符数组名或指针);gets()所在头文件:stdio.h语法:gets(字符数组名或指针);#if 1#include <stdio.h>int main(void) { // unsigned char a[10]= {'a','1','2','3','4','5','6','7','8','b'}; //没有结束符 ,数组必须以'\0'结束 unsigned char a[10]= {'a','1','2','3','4','5','6','7','8','\0'}; unsigned int b[10]= {0,1,2,3,4,5,6,7,8,9},i; unsigned char c[10]; sscanf(a, "%s", c); while(i<10){ printf("c is %c\n",c[i]); i++; } puts(c); //printf("\n%c\n", c[10]); //bug test puts("input a new c string!"); gets(c); //从键盘读取输入字符串到c数组 puts(c); //打印字符串 return 0;}#endif#if 0#include <stdio.h> int main() { const char* s = "iios/12DDWDFF等122"; char buf[20],a[20];sscanf( s, "%*[^/]/%[^等]", buf );//加*则是忽略第壹个读到得字符串sscanf( "15892acD", "%[1-9a-c]", a ); printf( "%s\n", buf );printf( "%s\n", a ); sscanf("hello, world","%*s%s", buf);printf("%s\n", buf); //worldreturn 0; } #endif
C语言基础
scanf()所在头文件:stdio.h语法:scanf(“格式控制字符串”,变量地址列表);接受字符串时:scanf(“%s”,字符数组名或指针);gets()所在头文件:stdio.h语法:gets(字符数组名或指针);#if 1#include <stdio.h>int main(void) { // unsigned char a[10]= {'a','1','2','3','4','5','6','7','8','b'}; //没有结束符 ,数组必须以'\0'结束 unsigned char a[10]= {'a','1','2','3','4','5','6','7','8','\0'}; unsigned int b[10]= {0,1,2,3,4,5,6,7,8},i; unsigned char c[10]; sscanf(a, "%s", c); while(i<10){ printf("c is %c\n",c[i]); i++; } puts(c); //printf("\n%c\n", c[10]); //bug test puts("input a new c string!"); gets(c); //从键盘读取输入字符串到c数组 puts(c); //打印字符串 return 0;}#endif#if 0#include <stdio.h> int main() { const char* s = "iios/12DDWDFF等122"; char buf[20],a[20];sscanf( s, "%*[^/]/%[^等]", buf );//加*则是忽略第壹个读到得字符串sscanf( "15892acD", "%[1-9a-c]", a ); printf( "%s\n", buf );printf( "%s\n", a ); sscanf("hello, world","%*s%s", buf);printf("%s\n", buf); //worldreturn 0; } #endif
亲们有问题可以在评论区提出偶,我将不定期给出解答,让我们一起进步一起成长!






