问题是这段代码不会交换这两个字符串.我是编程的新手,但我可以说问题是交换功能,但我不知道如何解决它.
我试图在交换中添加strcpy而不是"="但是没有用.
#include <stdio.h>
#include <stdlib.h>
void swap(char *t1, char *t2) {
char *t;
t=t1;
t1=t2;
t2=t;
}
int main() {
char *s[2] = {"Hello", "World"};
swap(s[0], s[1]);
printf("%s\n%s", s[0], s[1]);
return 0;
}
Run Code Online (Sandbox Code Playgroud)