鱼C论坛

 找回密码
 立即注册
查看: 1428|回复: 2

[已解决]出现异常

[复制链接]
发表于 2019-6-26 22:44:56 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#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[LIM][SIZE];
        char ch;
        int ct = 0;

        printf("Input up to %d lines.\n", LIM);
        while (ct < LIM && gets(input[ct]) != NULL && input[ct][0] != '\0')
        {
                //puts(input[ct]);
                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[LIM];
        for (i = 0; i < num; i++)
        {
        //        pt[i] = str[i];
                puts(str[i]);
        }
}

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[top], str1[seek]) > 0)
                        {
                                temp = str1[seek];
                                str1[seek] = str1[top];
                                str1[top] = temp;
                        }
                }
        for (i = 0; i < num; i++)
                puts(str1[i]);
}

为什么我无论选a还是b都会出现异常
最佳答案
2019-6-26 23:14:28
main.c:29:34: warning: passing argument 1 of 'original' from incompatible pointer type [-Wincompatible-pointer-types]
                         original(input,ct);
char input[LIM][SIZE];
char *str []

这是两个完全不同的类型
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2019-6-26 23:14:28 | 显示全部楼层    本楼为最佳答案   
main.c:29:34: warning: passing argument 1 of 'original' from incompatible pointer type [-Wincompatible-pointer-types]
                         original(input,ct);
char input[LIM][SIZE];
char *str []

这是两个完全不同的类型
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-6-26 23:17:47 | 显示全部楼层
第一个问题,先解决上个问题,这个a就能知道为什么了。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-3 23:29

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表