Need help with a print statement using arrays and structs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dru
    New Member
    • Sep 2006
    • 29

    Need help with a print statement using arrays and structs

    Code:
    int search(student_record db[], int count)
    {
    	int i;
    	char fname[30], lname[30];
    	printf("Enter the employees first name:\n");
    	scanf("%s",fname);
    	printf("Enter the employees last name:\n");
    	scanf("%s",lname);
    	printf("\n\n");
    	
    	for(i=0; i<count; i++)
    	{
    		if((strcmp(fname,db[i].firstname)==0) && (strcmp(lname,db[i].lastname)==0))
    		{
    			printf("Record Found!\n");
    			printf("Record[%d] = %s %s %s %s %s %s %s \n\n", i ,db[i].firstname,db[i].lastname,db[i].ssno,db[i].city,db[i].state,db[i].year,db[i].sex);
    			return i;
    		}
    		return -1;
    	}
    }
    This will find a record in my database but when it prints it will print the first element in the array. Which makes sense because on this line:
    Code:
    printf("Record[%d] = %s %s %s %s %s %s %s \n\n", i ,db[i].firstname,db[i].lastname,db[i].ssno,db[i].city,db[i].state,db[i].year,db[i].sex);
    it is using the variable of i as 0. I just need it to be able to print the record taht it found.
  • dru
    New Member
    • Sep 2006
    • 29

    #2
    Just moving it to the top to make sure it doesnt get missed.

    Comment

    • dru
      New Member
      • Sep 2006
      • 29

      #3
      Anyone got an idea?

      Comment

      Working...