坚信科学,分享技术

Tag Archives: sscanf

sscanf函数的各种用法

sscanf是一个运行时函数,原形很简单:  int sscanf(  const char *buffer,  const char *format [,  argument ] ...  );  它强大的功能体现在对format的支持上。  sscanf与scanf类似,都是用于输入的,只是后者以屏幕(stdin)为输入源,前者以固定字符串为输入源。      char str[512] = ;    sscanf("123456 ", "%s", str);    printf("str=%s", str); 输出 str=123456     sscanf("123456 ", "%4s", str);    printf("str=%s", str); 输出 str = 1234   sscanf("123456 abcdedf", "%[^ ]", str);    printf("str=%s", str); 输出 str=123456 (遇到空格为止)   sscanf("123456abcdedfBCDEF", "%[^A-Z]", str);    printf("str=%s", str); 输出 str=123456abcdef (遇到指定字符为止) …

Continue reading

Posted in linux, php | Tagged , , , | Leave a comment