program automatically exits at this point, so i presume the mistake is on this code:
for(k=0; k<cc; k++){
smallest = k;
for(j=k+1; j<cc; j++){
if (strcasecmp(pb[k].name, pb[j].name)>0){
smallest = j;
}
}
swapString(pb[k].name, pb[j].name);
}
the following are my initial declarations:
void swapString(char string1[], char string2[]){
char temp[31];
strcpy(temp, string1);
strcpy(string1, string2);
strcpy(string2, temp);
}
typedef struct myphonebook{
char name[31];
char address[101];
char cellphone[11];
char email[21];
} Myphonebooktype;
int main (int argc, char * argv[]){
Myphonebooktype*pb = NULL;
FILE*fp;
char username[16];
char password[16];
char option;
int i, k, j, cc, smallest;
is strcmp wrong? or i cannot compare strings inside struct? my goal is to sort my struct alphabetically. update: sorry, my mistake, it should be k
forloop which saysfor(k=0; i<cc; k++){did you mean to useirather thank? I.e. did you meanfor(k=0; k<cc; k++){smallest.swapString(pb[k].name, pb[j].name);meantswapString(pb[0..cc-1].name, pb[cc].name);,