Anyone who can help,
I"m starting to pull my hair out about this...I had to use scanf to read in the strings. I have been working on this lil project for 3 days and can't figure out how to print the strings after they have been swapped. Mine goes a lil something like this...
printf("\nThese are the names that you entered: \n\n");
for (i = 0; i < N_STRINGS; ++i)
printf("%s\n", s[i]);
for (i = 0; i < N_STRINGS; ++i)
for (k = i + 1; k < N_STRINGS; ++k)
if (strcmp(s[i], s[k]) == 1){
swap(s[i], s[k]);
}
printf("\nThe names that you entered are arranged alphabeticaly: \n\n");
for (i = 0; i < N_STRINGS; ++i)
printf("%s\n", s[i]);
printf("\n");
return 0;
}
void swap(char *p, char *q)
{
char tmp = *p;
*p = *q;
*q = tmp;
}
The first char of each string are the only things alphabetized; I need the whole string swapped. Please help!!
I"m starting to pull my hair out about this...I had to use scanf to read in the strings. I have been working on this lil project for 3 days and can't figure out how to print the strings after they have been swapped. Mine goes a lil something like this...
printf("\nThese are the names that you entered: \n\n");
for (i = 0; i < N_STRINGS; ++i)
printf("%s\n", s[i]);
for (i = 0; i < N_STRINGS; ++i)
for (k = i + 1; k < N_STRINGS; ++k)
if (strcmp(s[i], s[k]) == 1){
swap(s[i], s[k]);
}
printf("\nThe names that you entered are arranged alphabeticaly: \n\n");
for (i = 0; i < N_STRINGS; ++i)
printf("%s\n", s[i]);
printf("\n");
return 0;
}
void swap(char *p, char *q)
{
char tmp = *p;
*p = *q;
*q = tmp;
}
The first char of each string are the only things alphabetized; I need the whole string swapped. Please help!!
Comment