First off, indent your code properly: You have mixed styles in there:
struct employee{
char street[50],country[50],city[50];
int building_nb, zip;
} e[100];
int comparator(const void* p, const void* q)
{
return strcmp(((struct employee*)p)->country,((struct employee*)q)->country);
}
for (a = 0;a<n;a++)
{
if ((e[a].city == " ")||(e[a].city == "," && e[a+1].city == " ")||(e[a].city == "."))
space++;
}
for (; i < strlen(e[100].city); i++) {
if ((e[i].city == " ") || (e[i].city == "," && e[i+1].city == " ") || (e[i].city == ".")) {
spaceCnt = spaceCnt + 1;
}
}
which makes it hard to work out what the heck is going on, particularly when it all ends up with this:
return 0;
}
}
Either that
return
is in the wrong place, or you have something rather mixed up in your code.
And it make sit look like you found unrelated bits of code on the internet and threw them together in the hope it would all work...
Pick one style, and stick to it. It makes your code more readable, and laso reliable because you can see what is going on properly...
Now look at the error line:
p[i][k++] = e[j].city;
Look up what the various bits are declared as:
char p[20][50];
struct employee e[100];
struct employee{
char street[50],country[50],city[50];
int building_nb, zip;
}
So
city
is an array of char values - a
char*
- and
p[x][y]
is a
char
You are trying to put a pointer value into a
char
location and it is rightly telling you that's a bad idea.
Now, your code is confusing and difficult to read, so I have no idea what
p
is there for, or what you are actually trying to do. Using one character names for everything makes it easy for you to type, but it makes it really hard to work out what they are supposed to be used for or what the heck you are actually trying to do!
But I'd probably want to either copy the
city
string into the
p[x]
string, copy the
city
pointer into the
p[x]
pointer, or copy each character of the
city
string into each character of the
p[x][y]
locations.