C编程需要LValue [英] C programming LValue required
本文介绍了C编程需要LValue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
,我是C的初学者。
我有以下代码,我在第29,30和31行遇到错误。
错误是 - LValue必需。
,I am beginner to C.
I have the following code where i am getting error in Lines 29,30 and 31.
the error is - "LValue required".
#include<stdio.h>
#include<conio.h>
struct employee
{
char empname[30];
int leave;
};
void main()
{
struct employee a[1000];
int bp=5000, salary,x,i,j,k;
x=(bp*120)/100;
salary=bp+x;
printf("Enter the number of employees:");
scanf("%d",&j);
for(i=0;i<j;i++)>
{
printf("Enter employee name and number of days he/she took leave:");
scanf("%s%d",&a[i].empname, &a[i].leave);
}
for(i=0;i<j;i++)>
{
for(k=i+1;k<j;k++)>
{
if(a[i].empname[0]>a[k].empname[0])
{
char w[30];
int t;
w=a[i].empname;
a[i].empname=a[k].empname;
a[k].empname=w;
t[i]=a[i].leave;
a[i].leave=a[k].leave;
a[k].leave=t[i];
}
}
}
for(i=0;i<j;j++)>
{
if(a[i].leave>10)
salary=salary-((a[i].leave-10)*366);
}
for(i=0;i<j;i++)>
{
printf("Employee name = %s\nNumber of days leave = %d\nSalary = %d\n",a[i].empname,a[i].leave,salary);
}
getch();
}
你能帮我解决原因和正确的解决方案吗?
提前致谢。
- Venkatesh。
添加了代码块 - OriginalGriff [/ edit]
Can you please help me to knw the reason and the correct solution?
Thanks in advance.
- Venkatesh.
[edit]Code block added - OriginalGriff[/edit]
推荐答案
你有更大的问题就是这 - 看起来它是从一个组装而成套件......
正如理查德所说:你不能将变量声明为一个数组,然后期望复制数据并指定一个新指针。
但是......你也不能把>在for循环结束时,你不能使用整数作为数组,大多数年份没有366天...
我建议你尝试模块化这个程序:将其分为三个函数:一个用于获取输入,一个用于对数据进行排序,另一个用于输出。
然后获取每个函数在你继续写下一个之前工作 - 并且请让你的生活更轻松:停止使用一个角色名称。例如,要弄清楚j对employeeCount的作用要困难得多。请记住,您将在几周内回到此状态,现在让它可读,这意味着您可以节省下次工作时间。
You have bigger problems that just that - this looks like it was assembled from a kit...
As Richard says: you can't declare a variable as an array and then expect to copy the data bu assigning a new pointer.
But...You also can't put a ">" on the end of for loops, you can't use an integer as an array, and most years do not have 366 days...
I would suggest that you try to modularise this program: break it into three functions: One to get the inputs, one to sort the data, and one to output it.
Then get each one to work before you move on to writing the next - and please, to make your life easier: stop using one character names. It is a lot harder to work out what "j" does that it is for "employeeCount", for example. Remember, you will come back to this in a few weeks, and making it readable now means you save time working it all out next time.
这篇关于C编程需要LValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文