我有一个[错误] ld在C中返回1退出状态

时间:2016-02-17 01:18:57

标签: c

语言的,目前为我的最终项目编写了一个小代码。以下代码是最终产品的草稿。基本上它是一个评级系统,文件将在以后合并。但就目前而言,我只是试图测试程序,看看我的立场。我收到一个错误。 [错误] ld返回1退出状态。这是代码。

#include<stdio.h>
#include<conio.h>
#include<string.h>
int main ()  
{
    int use;
    int key;
    int pass,i; 
    int a;
    do
    {
        menu (a); 
        switch(a) 
        {
            case 1:
                for(i=1;i<5;i++) 
                {
                    printf("Please enter your username and password \n");
                    scanf("%d",&use);
                    printf("");
                    scanf("%d",& pass);
                    if (use ==711 && pass ==90210) 
                    { 
                        printf("\n Student Name");
                        printf("\n student subjects/student letter grade");
                        printf("\n");
                        printf("\n");
                        printf("\n");
                        printf("\t\t student GPA");
                        printf("\n Please enter any key to exit");
                        scanf("%d",& key);
                        break;
                    }
                }

            case 2:
                for(i=1;i<5;i++) 
                {
                    printf("Please enter your username and password \n");
                    scanf("%d",&use);
                    printf("");
                    scanf("%d",& pass);
                    if (use ==911 && pass ==90211) 
                    {
                        printf("Would you like to update student grades?");
                    }
                    break;
                }

            case 3:
                for(i=1;i<5;i++) 
                {
                    printf("Please enter your username and password \n");
                    scanf("%d",&use);
                    printf("");
                    scanf("%d",& pass);
                    if (use ==1011 && pass ==90215) 
                    {
                        printf("\n below the amount of users that accessed the system today");
                        printf("\n **********");
                        printf("\n");
                    }
                    break;
                    default:
                    printf("Please try agagin");
                }
        }
    } while (a!=4);
    return 0;                     

    getch();
}


int menu(a)
{
    printf("\t Welcome to Ski Academy Portal");
    printf("\n   1. Student \t");                                                                
    printf("\n   2. Staff \t");                                                                                                                                     
    printf("\n   3. Administrative \t");                                                   
    printf("\n   4.    Exit \t");          
    printf("\n Please enter your number choice \n");
    scanf("%d",&a);

    return 0;
}

1 个答案:

答案 0 :(得分:0)

您的错误似乎与menu在您尝试使用之前没有声明的事实有关。警告:

 warning: implicit declaration of function ‘menu’

相当不言自明。取决于编译器,它将流向链接阶段并生成ld returns -1 error,因为链接器无法找到名为menu的函数的定义。

在包含后,在代码顶部创建menu声明。 e.g。

...
#include<string.h>

int menu(a);

int main (void) {
...

或者最好:

int menu (int a);

另请注意'i''a'main()中未初始化使用。在尝试使用它们之前,请确保为它们提供值。

使用-Wall -Wextra进行编译(例如启用警告)将以简洁的方式告诉您所有这些。

相关问题