1.用strcat拼接函数可以实现
#include<stdio.h> #include<string.h> int main(int argc,char ** argv) { char str[100] = {0}; int i; for( i = 1; i < argc; i++) { strcat(str,argv[i]); } printf("str = %s ",str); return 0; }
2.用sprintf函数也可以实现
#include<stdio.h> int main(int argc,char **argv) { char buf[100] = {0}; int i,offset = 0; for( i = 1; i < argc; i++) { offset += sprintf(buf+offset,"%s",argv[i]); } printf("buf = %s ",buf); return 0; }
sprintf函数如果写入成功会返回写入字符的个数,第一个参数表示从字符串的第几位开始写入