Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 雇员结构_C_Xcode_Mingw_Sublimetext3 - Fatal编程技术网

C 雇员结构

C 雇员结构,c,xcode,mingw,sublimetext3,C,Xcode,Mingw,Sublimetext3,因此,我目前正在尝试学习C语言,完成一项任务,并且不断遇到相同的错误 上下文: 我要写一个有4个功能的程序- read_员工读取姓名、id和薪水,并将其存储在 然后返回的employee变量 打印员工读取员工结构,打印员工详细信息 employee\u total\u salary在一个参数中接受员工值数组 和另一个参数中数组的大小,并返回其所有参数的总和 员工索引搜索从员工结构中搜索ID 这是我被告知的密码: 1: Print the message "-- Enter Array 1 Emp

因此,我目前正在尝试学习C语言,完成一项任务,并且不断遇到相同的错误

上下文:

我要写一个有4个功能的程序-

read_员工读取姓名、id和薪水,并将其存储在 然后返回的employee变量

打印员工读取员工结构,打印员工详细信息

employee\u total\u salary在一个参数中接受员工值数组 和另一个参数中数组的大小,并返回其所有参数的总和

员工索引搜索从员工结构中搜索ID

这是我被告知的密码:

1: Print the message "-- Enter Array 1 Employee Data –"
2: Loop i for each index of test_array1
3: Assign test_array1 at index i, the result of calling read_employee
4: Print the message '-- Enter Array 2 Employee Data --'
5: Loop i for each index of test_array2
6: Assign test_array2 at index i, the result of calling read_employee
7: Print the message "-- Test Array 1 --"
8: Loop i for each index of test_array1
9: Call print_employee, passing in test_array1 at index i
10: Print 'Total : ', employee_total_salary ( test_array1, 5 )
11: Print the message '-- Test Array 2 --'
12: Loop i for each index of test_array2
13: Call print_employee, passing in test_array2 at index i
14: Print "Total : ", employee_total_salary ( test_array2, 10)
15: Store in i, the employee_index_search passing in test_array1 , and the id 123 and
size 5
16: if something was found
17: Call print_employee passing in the located computer from testArray1
18: else
19: Print the message " array 1 does not contain a employee with id 123"
这是我写的代码:

     #include <stdio.h>

struct employee{
    char name[20];
    int emp_id;
    float salary;
}; struct employee e[];

void read_employee ()
{
    int i = 0;
        printf("%dEnter Employee Name: ", i);
        scanf("%s", &e[i].name);
        printf("Enter in ID: ");
        scanf("%d", &e[i].emp_id);
        printf("Enter in Salary: ");
        scanf("%f", &e[i].salary);
       i++;
}

void print_employee(){
    for (int i = 0; i > 10; ++i)
    {
        if (e[i].salary < 4000)
        {
            printf("%s(%d):%f - Level A", e[i].name, e[i].emp_id, e[i].salary);
        }
        else if (e[i].salary > 5000)
        {
            printf("%s(%d):%f - Level B", e[i].name, e[i].emp_id, e[i].salary);
        }
        else
        {
            printf("%s(%d):%f", e[i].name, e[i].emp_id, e[i].salary);
        }
    }
}

//int employee_total_salary(){
    //int total;
    //sizeof(e.salary);

    //total = sizeof(e.salary) + e.salary;
    //return total;
//}

int employee_index_search(){
    int *id;
    int size = 5;

    for (int i = 0; i < size; i++)
    {
        if (e[i].emp_id == id)
        {
            printf("%s(%d):%f", e[i].name, e[i].emp_id, e[i].salary);
        }
        else
        {
            printf("Array 1 does not contain an employee with ID 123");
            return -1;
        }
    }
return 0;
}

int main(){
    int test_array1[5];
    int test_array2[10];
    int i;

    printf("\n-- Enter Array 1 Employee Data --\n");
    for (int i = 0; i < 5; i++)
    {
        read_employee(&test_array1[i]);
    }
    printf("\n-- Enter Array 2 Employee Data --\n");
    for (int i = 0; i < 10; i++)
    {
        read_employee(&test_array2[i]);
    }
    printf("-- Test Array 1 --\n");
    for (int i = 0; i < 5; ++i)
    {
        print_employee(&test_array1[i]);
    }
    //printf("Total:");
    //gets(employee_total_salary(test_array1, 5));
    printf("-- Test Array 2 --\n");
    for (int i = 0; i < 10; ++i)
    {
        print_employee(&test_array2[i]);
    }
    return 0;
    //printf("Total:");
    //gets(employee_total_salary(test_array2, 10));
    //employeee_index_search();
}
有人能告诉我哪里出了问题吗?程序也不会调用print_employee并打印数组 我评论了其中一些,因为我想先尝试至少1-2个工作函数

scanf("%d", &read.emp_id);
你应该换成

scanf("%d", &read[i].emp_id);
当您通过时,读取为结构的数组


您还缺少main和employee_total_salary的参数括号

read和p是指针类型!!!!print_employee没有返回值。欢迎使用StackOverflow。请坐飞机。请允许我推荐一个基本教程,一个演示编写函数的教程,你似乎错过了一些关于它们语法的细节。
scanf("%d", &read[i].emp_id);