簡體   English   中英

錯誤:c:87 :(。text + 0x247):重定位被截斷以適合:R_X86_64_PC32針對未定義的符號“ course_insert”

[英]Error: c:87:(.text+0x247): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `course_insert'

我是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);
    }
}

問題是語法錯誤。 course_insert()的函數定義在branching()的函數定義的大括號內。 您需要修復花括號:

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM