出现异常
#include <stdio.h>#include <string.h>
#define LIM 10
#define SIZE 81
void menu(void);
void original(char *str [], int num);
void order_ascii(char *str1[], int num);
int main(void)
{
char input;
char ch;
int ct = 0;
printf("Input up to %d lines.\n", LIM);
while (ct < LIM && gets(input) != NULL && input != '\0')
{
//puts(input);
ct++;
}
menu();
while ((ch = getchar()) != 'q')
{
switch (ch)
{
case 'a':
original(input,ct);
break;
case 'b':
order_ascii(input,ct);
break;
case 'c':
case 'd':
default:
printf("q to quit,not other words.\n");
break;
}
menu();
}
puts("Bye!");
getchar();
return 0;
}
void menu(void)
{
printf("You have five choices.\n");
printf("a、Print a list of source strings.\n");
printf("b、Print strings in order in ASCII.\n");
printf("c、Print strings in incremental order of length.\n");
printf("d、Print the string by the length of the first word in the string.\n");
printf("q、QUIT.\n");
}
void original(char *str [],int num)
{
int i;
//char *pt;
for (i = 0; i < num; i++)
{
// pt = str;
puts(str);
}
}
void order_ascii(char *str1[], int num)
{
char *temp;
int top, seek;
int i;
for(top = 0;top<num-1;top++)
for (seek = top + 1; seek < num; seek++)
{
if (strcmp(str1, str1) > 0)
{
temp = str1;
str1 = str1;
str1 = temp;
}
}
for (i = 0; i < num; i++)
puts(str1);
}
为什么我无论选a还是b都会出现异常 main.c:29:34: warning: passing argument 1 of 'original' from incompatible pointer type [-Wincompatible-pointer-types]
original(input,ct);
char input;
char *str []
这是两个完全不同的类型
第一个问题,先解决上个问题,这个a就能知道为什么了。
页:
[1]