Searching structure piece

This is a discussion on Searching structure piece within the C Programming forums, part of the General Programming Boards category; I have an structure array containg information about students of a class. The Information was read from a file into ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    3

    Searching structure piece

    I have an structure array containg information about students of a class. The Information was read from a file into the structures. I then display this information and ask the user to pick a student by entering their ID number, i then send the ID and the structure of students to a function and search the structure for that student and specifically display their information only. I have this .. a function that supposed to search and compare students ID with the user entered ID, and print out that students information.

    Code:
    void find_applicant(struct school *student, char ID[10], int NumEmp)
    {
    	int i;
    
    	for(i=0; i<NumEmp; i++)
    	{
    		if(strcmp(ID, student[i].appnum) = 0)
    		{
    			printf("%s\n", student[i].appnum);
    			printf("%s\n", student[i].fname);
    			printf("%s\n", student[i].lname);
    			printf("%10.0lf\n", studen[i].pnum);
    			printf("%s\n", student[i].email);
    			printf("%d\n", student[i].numskl);
    			printf("%d\n", student[i].year);
    			printf("%s\n", student[i].make);
    			printf("%s\n\n\n", student[i].mod);
    		}	
    	}
    }
    it keeps telling me "invalid lvalue assignment" for the line with strcmp. I don't understand the problem. Thanks for any help or advice given.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Code:
    if(strcmp(ID, student[i].appnum) = 0)
    This is an (attempted) assignment.
    Code:
    if(strcmp(ID, student[i].appnum) == 0)
    This is a comparison.

    [EDIT]
    Code:
    printf("%10.0lf\n", studen[i].pnum);
    This is undefined behavior.
    [/EDIT]
    Last edited by Dave_Sinkula; 10-20-2003 at 08:51 PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need a second opinion - code error and i cant see it
    By bigfootneedhelp in forum C Programming
    Replies: 19
    Last Post: 10-25-2007, 06:02 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Visual C++ 2005 linking and file sizes
    By Rune Hunter in forum C++ Programming
    Replies: 2
    Last Post: 11-12-2005, 09:41 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 09:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21