错误:c:87 :(。text + 0x247):重定位被截断以适合:R_X86_64_PC32对未定义的符号`course_insert'

时间:2017-03-20 02:40:41

标签: c

我是C的新手,我正试图弄清楚世界上是什么导致了这一点。另一个类似的问题说我必须下载另一个库,但这还没有解决问题。所以,希望有人能发现我的问题。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

enum Subject {SER=0, EGR=1, CSE=2, EEE=3} subject;

struct Course {
    enum Subject subject;
    int number;
    char teacher[1024];
    int hours;
}   *course;


//place to store course information
struct Course* CourseCollection = NULL;

//number of courses in the collection. also the index of the next empty element.
int courseCount = 0;


void branching(char option);

void course_insert(struct Course course);

int main() {
    char input_buffer;
    printf("Welcome to ASU Class Schedule\n");

    //menu and input loop
    do {

        printf("\nMenu Options\n");
        printf("------------------------------------------------------\n");
        printf("a: Add a class\n");
        printf("d: Drop a class\n");
        printf("s: Show your classes\n");
        printf("q: Quit\n");
        printf("\nTotal Credits: %d\n\n", courseCount);
        printf("Please enter a choice ---> ");

        scanf(" %c", &input_buffer);

        branching(input_buffer);
    } while (input_buffer != 'q');

    return 0;
}

//takes a character representing an inputs menu choice and calls the appropriate
//function to fulfill that choice. display an error message if the character is
//not recognized.

void branching(char option) {
    int prefix, courseNum, credits;
    char instructor;
    struct Course course1;

    switch(option) {
    case 'a' : 
        printf("Adding a class");
        printf("\nWhat is the subject (SER=0, EGR=1, CSE=2, EEE=3)? ");
        scanf(" %d", &prefix);
        course1.subject = prefix;
        printf("\nWhat is the course number (e.g. 334)? ");
        scanf(" %d", &courseNum);
        course1.number = courseNum;
        printf("\nHow many credits is the class? ");
        scanf(" %d", &credits);
        course1.hours = credits;
        printf("\nWhat is the name of the teacher? ");
        scanf(" %s", &instructor);
        strlcpy(course1.teacher, instructor, 1024);
        printf(" %s %d", course1.subject, course1.number);
        courseCount++;
        course_insert(course1);
        break;
    case 'd' :
        // TODO
        break;
    case 's' :
        // TODO
        break;
    case 'q' :
        printf("Goodbye ");
        break;
    default :
        printf("Error: Invalid Input. Please Try Again. ");
        break;
    }

    void course_insert(struct Course course) {
        CourseCollection = malloc(sizeof(course)*courseCount);
    }
}

1 个答案:

答案 0 :(得分:1)

问题是语法错误; course_insert()的函数定义位于branching()函数定义的花括号内。你需要修复花括号:

void branching (char option)
{
    // Code for function
} 

void course_insert(struct Course course)
{
    CourseCollection = malloc(sizeof(course)*courseCount);
}