Hello,
I am writing a c program to Prompts the user (altogether 10 times) to enter a word not longer than 9 characters. And it needs the modification of each word by changing lower case to upper and then the reverse of the word is concatenated with the word.FInally , show them in unsorted way and sorted way.
After that, the program terminates. I have made many attempts at writing this program and this is where i am at right now and it still doesnt work. Thanks in advance for the input.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char toupper(char);
char tolower(char);
int main(void)
{
char words[10][19];
char c;
int i, j;
int k;
char swap;
for(i = 0; i < 10; i++)
{
printf("enter the character \n");
fflush(stdout);
for (j = 0; j < 10; j++)
{
words[i][j] =fgetc(stdin);
if (words[i][j] == '\n')
{
words[i][j] = '\0';
} /* end of if */
}
}
for(i = 0; i < 10; i++){
for (j = 0; j < 10; j++){
k = (int)(words[i][j]);
if (k > 64 && < 91)
{
words[i][j]= tolower(words[i][j] );
}
else if (k >96 && <123);
{
words[i][j]= toupper(words[i][j] );
}
}
}
printf("unsort \n");
for(i = 0; i < 10; i++){
printf("%s \n ", words[i]);
fflush(stdout);
}
printf("Sorted: \n");
for(i=9; i>0; i--) {
for(j=0; j<i; j++) {
if (strcmp(words[j],words[j+1])>0) {
strcpy(swap,words[j]);
strcpy(words[j],words[j+1]);
strcpy(words[j+1],swap);
}
}
printf("%s \n", words[i]);
}
return 0;
}
char toupper(char let)
{
int d;
d = (int)let;
let = (char)d-32;
return let;
}
char tolower(char let)
{
int d;
d = (int)let;
let = (char)d+32;
return let;
}