用指针写了个用指针对3个字符串由小到大排序的题目,但是总是没找到哪错了,求解
程序代码:
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> int main() { void swap(char *p1,char *p2); char strings[3][80] = { "I study very hard.", "C language is very interesting.", "He is a professfor." }; int i; swap(strings[0],strings[1]); swap(strings[0],strings[2]); swap(strings[1],strings[2]); for (i = 0; i <= 2; i++) { printf("%s\n", strings[i]); } system("pause"); return 0; } void swap(char *p1, char *p2) { char *temp = NULL; if (strcmp(p1, p2) > 0) { strcpy(temp,p1); strcpy(p1,p2); strcpy(p2,temp); } }
编译器是这样反馈的信息
[ 本帖最后由 firewater 于 2015-2-25 22:53 编辑 ]