2个回答
展开全部
int strcpy(char *s1,const char *s2);
开辟一个缓冲区,比如
char buff[100];//假设你的字符串不超过这么多
而你的而为数组为
char **argv;
其中argv[0] = "this is the first string";
argv[1] = "this is the seconde string";
你只须调用如下
strcpy(buff,argv[0]);
strcpy(argv[0],argv[1]);
strcpy(argv[1],buff);
一下是完整代码,并测试过
#include <stdio.h>
#include <string.h>
char argv[2][100]={ "This is the first string","This is the second string"};
// 存储字符串的二维数组,每个字符串最长为99个字节
char buff[100];
//缓冲区
int main()
{
printf("转换前:\n");
printf("argv[0] = %s\n",argv[0]);
printf("argv[1] = %s\n",argv[1]);
strcpy(buff,argv[0]);
strcpy(argv[0],argv[1]);
strcpy(argv[1],buff);
printf("转换后:\n");
printf("argv[0] = %s\n",argv[0]);
printf("argv[1] = %s\n",argv[1]);
return 0;
}
开辟一个缓冲区,比如
char buff[100];//假设你的字符串不超过这么多
而你的而为数组为
char **argv;
其中argv[0] = "this is the first string";
argv[1] = "this is the seconde string";
你只须调用如下
strcpy(buff,argv[0]);
strcpy(argv[0],argv[1]);
strcpy(argv[1],buff);
一下是完整代码,并测试过
#include <stdio.h>
#include <string.h>
char argv[2][100]={ "This is the first string","This is the second string"};
// 存储字符串的二维数组,每个字符串最长为99个字节
char buff[100];
//缓冲区
int main()
{
printf("转换前:\n");
printf("argv[0] = %s\n",argv[0]);
printf("argv[1] = %s\n",argv[1]);
strcpy(buff,argv[0]);
strcpy(argv[0],argv[1]);
strcpy(argv[1],buff);
printf("转换后:\n");
printf("argv[0] = %s\n",argv[0]);
printf("argv[1] = %s\n",argv[1]);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询