Problem when trying to sort struct members

There seems to be no problem in sorting the ISBN, I'm assuming because its just numbers. The other struct members are all char strings and don't want to be moved in the same way.
I need the book title, author, and publisher to follow with its corresponding ISBN, but the compiler keeps throwing me "left operand must be l-value" errors.
This is for a first year programming class so I'm sure there is some relatively simple solution I'm overlooking.

Thank you in advance!

1
2
3
4
5
6
7
8
9
10
11
//this is all up top before main
 struct library
{
	char title[30];
	char author[30];
	char publisher[30];
	int isbn;

};
struct library book[50];     
int n = 0;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
void sortfile(void){
  int j;
  int holdi;
  char holdc[30];

  if (n < 1)                            // check for empty list
    printf("\nEmpty list.\n");
    for (j = 0; j < n; j++){ //passes
      printf("\n Sort Complete! press 'l' to view the sorted list\n");
    for (int pass = 0; pass < n + 1; pass++) {	// passes
      for (j = 0; j < n - 1; j++)
        if (book[j].isbn > book[j + 1].isbn){
  	  holdi = book[j].isbn;
	  book[j].isbn = book[j + 1].isbn;
	  book[j + 1].isbn = holdi;  // this all works perfectly

	// I need to be able to do the same with my other struct members, but I'm having troubles
	  holdc[30] = book[j].author;
	  book[j].author = book[j + 1].author;
	  book[j + 1].author = holdc[30];

	}
   }
}
}

You cannot assign arrays around like that. In your case you need to either use strncpy to copy strings, or assign structs as whole instead of manually switching their innards
Topic archived. No new replies allowed.