繁体   English   中英

在C函数中引用的未解析的外部符号_printf

[英]unresolved external symbol _printf referenced in function in C

我已经阅读了一些解决方案,例如更改链接器,include /甚至清理了整个项目。 似乎无法解决我面临的这个问题。

Error   LNK2019 unresolved external symbol _print referenced in function _sortEmployees

我只是想运行sortedEmployees函数

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

int main(void){
    /*You are NOT allowed to modify the code of this function*/
    sortEmployees(sampleEmployeeList);
    readFromFile("employees.txt");
    Node *head = youCanIgnoreThisFunction(sampleEmployeeList);
    Node *employeeNode = malloc(sizeof(Node));
    Employee e = { "Newbie", 10000 };
    employeeNode->employee = e;
    addNode(employeeNode, head, 0);
    getch();
}

void sortEmployees(Employee elist[]){
    printf("EMPLOYEE REPORT\n");
    printf("%-25s%-10s\n", "Employee_name", "Salary");
    printf("%-25s%-10s\n", "------------", "-----");

    int i, j;
    Employee temp;
    for (i = 0; i < MAX; i++) {
        printf("%-25s%-10s\n", elist[i].name,elist[i].salary);
    }
    print("After Sorting");

    for (i = 0; i < MAX -1; i++) {
        for (j = i + 1; j < MAX; j++) {
            if (strcmp(elist[j].name, elist[j + 1].name) > 0) {
                temp = elist[j];
                elist[j] = elist[j + 1];
                elist[j + 1] = temp;
            }
        }
    }
    for (i = 0; i < MAX; i++) {
        printf("%-25s%-10s\n", elist[i].name, elist[i].salary);

    }

}

void readFromFile(char fileName[]){

    FILE *filePtr = fopen(fileName, "r");
    if (filePtr == NULL){
        printf("File could not be opened\n");
        return;
    }
    printf("\nEmployee list from file %s\n", fileName);
    printf("%-25s%-10s\n", "Employee_name", "Salary");
    printf("%-25s%-10s\n", "------------", "-----");
    char name[20];
    int examScore;

    /*not done*/

    fclose(filePtr);
}

void addNode(Node *nodePtr, Node *headPtr, int pos){


    /*not done*/
    printEmployeeList(headPtr);
}



void printEmployeeList(Node *headPtr){
    /*You are NOT allowed to modify the code of this function*/
    printf("%-25s%-10s\n", "Employee_name", "Salary");
    printf("%-25s%-10s\n", "------------", "-----");
    while (headPtr != NULL){
        printf("%-25s%-10d\n", headPtr->employee.name, headPtr->employee.salary);
        headPtr = headPtr->next;
    }
}

Node *youCanIgnoreThisFunction(Employee employeeList[]){
    /*You are NOT allowed to modify the code of this function*/
    Node *list = NULL;

    for (int i = 0; i < MAX; i++)
    {
        Node *employeeNode = malloc(sizeof(Node));
        employeeNode->employee = employeeList[i];
        list = youCanIgnoreThisFunctionToo(employeeNode, list);
    }
    return list;
}

Node *youCanIgnoreThisFunctionToo(Node *nodePtr, Node *headPtr){
    /*You are NOT allowed to modify the code of this function*/
    nodePtr->next = headPtr;
    headPtr = nodePtr;
    return headPtr;
}

尝试更换

print("After Sorting");

printf("After Sorting");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM