I am trying to make a multi-program database in C.
我正在尝试用C语言编写一个多程序数据库。
Here is the code:
这是代码:
#include<stdio.h>
#include<stdlib.h>
#include "function.c"
int main()
{
info();
example();
printf("\n\n\n");
char name[1][10], id[1][10], grade[1][1];
char choice;
int x=0;
int sal[1];
FILE *fp;
printf("Would you like to continue? Y/N: ");
scanf("%c",&choice);
fflush(stdin);
if(choice == 'Y' || choice == 'y')
{
system("cls");
fp = fopen("database.txt","w");
if(fp == NULL)
{
printf("File does not exist!");
return 0;
}
else
{
while(x<=1)
{
printf("Enter Employee name no.%d: ",(x+1));
scanf("%s",name[x]);
fprintf(fp, "Employee Name: %s\n",name);
printf("Enter Employee ID: ");
scanf("%s",id[x]);
fprintf(fp, "Employee ID: %s\n",id);
printf("Enter Employee Grade Level (A-E): ");
scanf("%s",grade[x]);
fprintf(fp, "Employee Grade Level: %s\n",grade);
printf("Enter Employee's Basic Salary: ");
scanf("%d",&sal[x]);
fprintf(fp, "Employee's Basic Salary: %d\n\n\n",sal);
printf("Employee's bonus: %d\n",bonus(grade[x],sal[x]));
printf("Employee's allowance: %d\n",allowance(grade[x], sal[x]));
printf("\n");
}
}
fclose(fp);
}
else
{
return 0;
}
return 0;
}
function.c :
函数。c:
#include<stdio.h>
#include "function.h"
int bonus(char *grade[1][], int *sal[])
{
int bonus;
int *b;
int x;
b = &bonus;
for(x=0;x<=1;x++)
{
switch(*grade[x])
{
case 'A':
bonus = (1/4) * *sal[x];
break;
case 'B':
bonus = (1/5) * *sal[x];
break;
case 'C':
bonus = (15/100) * *sal[x];
break;
case 'D':
bonus = (1/10) * *sal[x];
break;
case 'E':
bonus = (5/100) * *sal[x];
break;
default:
printf("Invalid Choice!!");
break;
}
return bonus;
}
}
int allowance(char *grade[1][], int *sal[])
{
int all;
int *a;
int x;
a = &all;
for(x=0;x<=1;x++)
{
switch(*grade[x])
{
case 'A':
all = (3/10) * *sal[x];
break;
case 'B':
all = (6/25) * *sal[x];
break;
case 'C':
all = (9/50) * *sal[x];
break;
case 'D':
all = (3/25) * *sal[x];
break;
case 'E':
all = (3/50) * *sal[x];
break;
default:
printf("Invalid Choice!!");
break;
}
return all;
}
}
function.h:
function.h:
#ifndef _FUNCTION_H_INCLUDED
#define _FUNCTION_H_INCLUDED
int bonus(char *grade[][], int *sal[]); //prototype for calculating bonus
int allowance(char *grade[][], int *sal[]); //prototype for allowance
void info(); //prototype for information
void example(); //prototype for example
#endif
When I try to compile the program, I get:
当我试图编译程序时,我得到:
2 0 function.c In file included from function.c
4 17 function.h [Error] array type has incomplete element type
5 21 function.h [Error] array type has incomplete element type
4 17 function.c [Error] array type has incomplete element type
function.c In function 'bonus':
18 19 function.c [Error] invalid operands to binary * (have 'int' and 'int *')
21 19 function.c [Error] invalid operands to binary * (have 'int' and 'int *')
24 22 function.c [Error] invalid operands to binary * (have 'int' and 'int *')
27 20 function.c [Error] invalid operands to binary * (have 'int' and 'int *')
30 21 function.c [Error] invalid operands to binary * (have 'int' and 'int *')
function.c At top level:
41 21 function.c [Error] array type has incomplete element type
function.c In function 'allowance':
54 17 function.c [Error] invalid operands to binary * (have 'int' and 'int *')
57 17 function.c [Error] invalid operands to binary * (have 'int' and 'int *')
60 17 function.c [Error] invalid operands to binary * (have 'int' and 'int *')
63 17 function.c [Error] invalid operands to binary * (have 'int' and 'int *')
66 17 function.c [Error] invalid operands to binary * (have 'int' and 'int *')
I do not know what the problem is (I'm a beginner in C programming).
我不知道问题是什么(我是C编程的初学者)。
My first question: What does array type has incomplete element type mean? Next question: Why am I still getting the invalid operands to binary * error?
我的第一个问题:数组类型有什么不完整的元素类型?下一个问题:为什么我仍然将无效的操作数变成二进制*错误?
Any help would be appreciated.
如有任何帮助,我们将不胜感激。
2 个解决方案
#1
2
for "My first question: What does array type has incomplete element type mean?"
对于“我的第一个问题:数组类型有不完整的元素类型意味着什么?”
this error occur because in c language you need to specify the array size if you are not declaring it like
这个错误发生是因为在c语言中,如果您没有声明它,您需要指定数组大小。
int arr[] = {6,1,2,3};
arr int[]= { 6,1、2、3 };
otherwise
否则
it should be int arr[<size of the array>];
它应该是int arr[ <数组> 的大小];
for invalid operands to binary * error?
对于无效的操作数到二进制*错误?
it occurs because you are trying to multiply int
and int *
values
它之所以发生,是因为您试图将int和int *值相乘。
consider seeing this http://forums.devshed.com/c-programming-42/dynamic-arrays-with-undeclared-size-62036.html
考虑看到这个http://forums.devshed.com/c编程- 42/dynamic数组- -未申报的大小- 62036. - html
and read some more tutorials about pointers and arrays and how to mix them
并阅读一些关于指针和数组的教程,以及如何混合它们。
#2
1
In the declarations in function.h
, you have:
在函数的声明中。h,你有:
int bonus(char *grade[][], int *sal[]);
You can't leave out all the dimensions; you have to specify a number for every dimension of an array except, perhaps, the first. For example, this might be legitimate:
你不能忽略所有的维度;您必须为数组的每个维度指定一个数字,除了第一个。例如,这可能是合法的:
int bonus(char *grade[][20], int *sal[]);
I've not checked whether 20 is the appropriate number, but some number must be used in the context.
我没有检查20是否是合适的数字,但是一定要在上下文中使用一些数字。
This is causing the 'incomplete array type' message.
这导致了“不完全数组类型”消息。
#1
2
for "My first question: What does array type has incomplete element type mean?"
对于“我的第一个问题:数组类型有不完整的元素类型意味着什么?”
this error occur because in c language you need to specify the array size if you are not declaring it like
这个错误发生是因为在c语言中,如果您没有声明它,您需要指定数组大小。
int arr[] = {6,1,2,3};
arr int[]= { 6,1、2、3 };
otherwise
否则
it should be int arr[<size of the array>];
它应该是int arr[ <数组> 的大小];
for invalid operands to binary * error?
对于无效的操作数到二进制*错误?
it occurs because you are trying to multiply int
and int *
values
它之所以发生,是因为您试图将int和int *值相乘。
consider seeing this http://forums.devshed.com/c-programming-42/dynamic-arrays-with-undeclared-size-62036.html
考虑看到这个http://forums.devshed.com/c编程- 42/dynamic数组- -未申报的大小- 62036. - html
and read some more tutorials about pointers and arrays and how to mix them
并阅读一些关于指针和数组的教程,以及如何混合它们。
#2
1
In the declarations in function.h
, you have:
在函数的声明中。h,你有:
int bonus(char *grade[][], int *sal[]);
You can't leave out all the dimensions; you have to specify a number for every dimension of an array except, perhaps, the first. For example, this might be legitimate:
你不能忽略所有的维度;您必须为数组的每个维度指定一个数字,除了第一个。例如,这可能是合法的:
int bonus(char *grade[][20], int *sal[]);
I've not checked whether 20 is the appropriate number, but some number must be used in the context.
我没有检查20是否是合适的数字,但是一定要在上下文中使用一些数字。
This is causing the 'incomplete array type' message.
这导致了“不完全数组类型”消息。