如:
//把整数123 打印成一个字符串保存在s 中。
sprintf(s, "%d", 123); //产生"123"
可以指定宽度,不足的左边补空格:
sprintf(s, "%8d%8d", 123, 4567); //产生:" 123 4567"
strchr函数
功能:查找字符串s中首次出现字符c的位置
说明:返回首次出现c的位置的指针,如果s中不存在c则返回NULL。
#include#include int main(void) { char string[17]; char *ptr, c = 'r'; strcpy(string, "This is a string"); ptr = strchr(string, c); if (ptr) printf("The character %c is at position: %dn", c, ptr-string); else printf("The character was not foundn"); return 0; }
运行结果:The character r is at position: 12
结合起来使用
sprintf(local + pos, "%s", strchr(emails[i], '@'));
local 是一个char类型的数组,pos是位置,email是字符串数组
这句代码的意思就是,在email[i]中找到@的位置,返回的是@这个字符的指针,然后将这个字符及后边的字符串加到local的第pos个位置及后边



