473,507 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

non-lvalue in assignment ERROR

1 New Member
I'm trying to write a program for sorting students by their names with structures and pointers, but I get messages in lines 34 and 35
"non-lvalue in assignment".Here is the code and image.
And I must say,I'm very new in programming.

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<math.h>
  4. #define LOOP for(i=0;i<n;i++)
  5. #include<string.h>
  6.  
  7. struct date {int day,mo,year;};
  8. struct fax {char name[20]; int index; date birth;};
  9.  
  10. main()
  11. {
  12.    int i,n;
  13.  
  14.     printf("How many students ");
  15.     scanf("%d",&n);
  16.  
  17.       fax *pStudent;
  18.       pStudent=(fax*)malloc(n*sizeof(fax));
  19.       LOOP
  20.       {
  21.       printf("Name:"); scanf("%s",(pStudent+i)->name);
  22.       printf("Index:"); scanf("%d",&(pStudent+i)->index);
  23.       printf("Date of birth:"); scanf("%d %d %d",&((pStudent+i)->birth.day),&((pStudent+i)->birth.mo),&((pStudent+i)->birth.year));
  24.       }
  25.  
  26.  
  27.       void *pom;
  28.  
  29.     LOOP /* in this loop i'm sorting students by their names*/
  30.          for(int j=i+1;j<n;j++)
  31.                   if(  strcmp((pStudent+i)->name,(pStudent+j)->name)>0  )
  32.       {
  33.        pom=pStudent+i;
  34.       (pStudent+i)=(pStudent+j); 
  35.        (pStudent+j)=pom;
  36.       }
  37.  
  38.      puts("Students sorted by name");
  39.  
  40.      LOOP
  41.      printf("%s %d",(pStudent+i)->name,(pStudent+i)->index);
  42.  
  43.       system("pause");
  44.       }
  45.  
Jun 11 '10 #1
1 4438
Banfa
9,065 Recognized Expert Moderator Expert
An lvalueis (crudely) a value or expression that can appear on the left hand side of an assignment.

So what is (pStudent+i)? Well lets start with what type is (pStudent+i). Well pStudent is a fax* so the type of (pStudent+i) is also fax* since (pStudent+i) is just pointer arithmetic resulting a pointer to the fax i after pStudent.

If (pStudent+i) is fax* then (pStudent+i)=(pStudent+j) must be pointer assignment, but hang on (pStudent+i) is not a pointer with a memory location it is a calculated value with no memory location for you to assign a value to. It is an rvalue not an lvalue hence the compiler error.

At line 18 you allocate an array of fax objects when you do you sort you there need to work on fax objects when swapping values in the array, not fax* pointers.
Jun 11 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
4398
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few...
17
3252
by: cheeser | last post by:
Hello all, Please see the question in the code below... Thanks! Dave #include <iostream>
5
3727
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
3
12189
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in...
1
6885
by: Markus Ernst | last post by:
Hi I wrote a function that "normalizes" strings for use in URLs in a UTF-8 encoded content administration application. After having removed the accents from latin characters I try to remove all...
25
7543
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
32
4468
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
8
3485
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I...
11
3395
by: ypjofficial | last post by:
Hello All, So far I have been reading that in case of a polymorphic class ( having at least one virtual function in it), the virtual function call get resolved at run time and during that the...
399
12635
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7110
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.