微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

C – 参数名称省略?

所以和class级工作一起进步,学习C

我决定按照上下文所示的课堂作业,按照我的简要内容逐步安排function,试图逐一解决代码问题:

结构图

function简介

获取我自己的应用程序的最上方窗口 – 在C中

覆盖C#中面板的控件属性

内存布局问题

如何在Windows中获取操作系统名称,版本?

链接Windows 7上的.lib文件

代码被告知遵循:

use #define SIZE 3 function : main ----------------------- Local variables: - emp_array (an array of 3 employee detail values) - i (an integer used as the index for the arrays) - char str[20] to read in name of employee for search ----------------------- 1: call read_all_employee,passing in emp_array and SIZE 2: Print the message 'Employee details are' 3: call print_all_employee,passing in emp_array and SIZE 4: Print 'Total : ',employee_total_salary (emp_array,SIZE) 5: Print the message '—Employee with the largest salary is --' 6: Store in i,the search_largest_salary_index passing in emp_array and SIZE 7: Call print_employee,passing in emp_array at index i 8: Print the message '— Enter employee name for the search--' 9: read in the name in str array 10: Store in i,the search_an_employee_salary passing in emp_array,SIZE and str 11: if something was found 12: Print the message 'The salary of xxxx is xxxx' 13: else 14: Print the message "Array does not contain an employee named xxxx" 15: Print the message '—Employee details in reverse order are --' 16: Loop i starting from 2 to 0 for each index of emp_array 17: Call print_employee,passing in emp_array at index i

但编译程序,我不断遇到错误'参数名称省略'的每个函数,其中大小声明插入#define size 3后,')'名称预期

这是我迄今写的代码

#include <stdio.h> #define size 3 struct employee{ char name[20]; int emp_id; float salary; }; struct employee read_employee(){ struct employee r_employee; printf("Enter Employee Name: "); scanf("%s",&r_employee.name); printf("Enter ID: "); scanf("%d",&r_employee.emp_id); printf("Enter Salary: "); scanf("%f",&r_employee.salary); while (r_employee.salary < 0){ printf("This is not a valid price,enter againn"); scanf("%f",&r_employee.salary); } return r_employee; } struct employee read_all_employee(struct employee emp_array[],int size){ for (int i = 0; i < size; ++i) { emp_array[i] = read_employee(); } } void print_employee(struct employee employee_data){ printf("%s(%d): %fn",employee_data.name,employee_data.emp_id,employee_data.salary); if (employee_data.salary > 5000) { printf("Level An"); } if (employee_data.salary < 4000) { printf("Level Bn"); } } float employee_total_salary(struct employee emp_array[],int size){ int i; float sum = 0; for (int i = 0; i < size; i++) { sum = sum + employee_array[i].salary; } return sum; } int employee_index_search(struct employee emp_array[],int id,int size){ int i; for (int i = 0; i < size; i++) { if (employee_array[i].emp_id == id) { return i; } } return -1; } int main(){ struct employee emp_array[3]; int i; char str[20]; printf("Line 1:n"); read_all_employee(emp_array,size); printf("Employee Details are:n"); return 0; }

有人可以请更正我的代码到目前为止?

拖放到winapi

DataGridView不填充

Directory.EnumerateFilesexception

如何定义task.json通过在Windows上使用cl.exe来编译vscode中的C / C ++代码

Linux 2.6.30 uClibc 0.9.29 pthread_create两个脚步只有一个

参数名称省略

意思是说,编译器在预期的地方看不到参数名称

这是因为你不能使用define和名称相同的参数名称。 在编写#define size 3 ,预处理器将其在代码中看到的每个size替换为3 ,然后在调用具有参数size的函数而不是struct employee read_all_employee(...,int size) ,会得到struct employee read_all_employee(...,int 3) ,导致int类型的参数没有有效的名字('3'不是一个有效的名字) 。

我建议使用带有CAPS的define ,或者使用一些独特的名称,这样你就不会感到困惑,比如SIZE或者只是记住你有size符号,并且在你的函数中使用了其他的参数名,例如input_size

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐