指针不好学
程序代码:
#include<stdio.h> #include<string.h> int compare(char *p1, char *p2) { int i = 0, j = 0; int m, n, p, c; m = strlen(p1); n = strlen(p2); while ((m >= n ? p1[i] : p2[i]) != '\0') { if (p1[i] == p2[j]) p = 1; else { c = p1[i] - p2[j]; p = 0; break; } i++; j++; } if (p == 1) return 0; else return c; } void input(char *p1, char *p2) { printf("input string 1:\n"); gets_s(p1, 80); printf("input string 2:\n"); gets_s(p2, 80); } void print(int c) { printf("%d\n", c); } int main() { void input(char *p1, char *p2); int compare(char *p1, char *p2); void print(int c); int c; char a[80], b[80]; char *p1, *p2; p1 = a; p2 = b; input(p1, p2); c = compare(p1, p2); print(c); return 0; }