Hi everyone. I'm new to the forums, as well a C programming as well, so bare with me for any noob mistakes. I have a homework assignment I am working on now, and am just completely stumped. The assignment calls for the following
The user is to input 10 words. It then takes those words, changes the lower and upper case around (were not allowed using the toupper() or tolower () functions), as well as spelling those words backwards. Heres a brief example
Enter Word 1: tHe
Enter Word 2: seCOND
Enter Word 3: wOrD
... etc etc up until the 10th word
The output would then be the following:
EhTThE
dnocESSEcond
dRoWWord
Everyone catch my drift. Now from this, I must take the unsorted output, and bubble sort it in ascending order. Here is the code I have come up with. Any help is greatly appreciated
#include <stdio.h>
#include <string.h>
int main(void)
{
char Word[10][19];
int i, j, k, l, z;
int value;
char swap[19];
char ch;
for(z=0 ; z<10 ; z++)
{
if (z == 0)
printf("Enter the 1st word: ");
else if (z == 1)
printf("Enter the 2nd word: ");
else if (z == 2)
printf("Enter the 3rd word: ");
else
printf("Enter the %dth word: ",z+1);
i=0;
while(( ch = fgetc(stdin)) != '\n')
{
i=i+1;
Word[z][i]= ch;
}
l=10;
for(k=i ; k>=1; k--)
{
Word[z][l]=Word[z][k];
l=l++;
}
Word[z][19]=i;
}
printf("\n");
printf("Unsorted Input: \n");
printf("\n");
for (z=0 ; z<10 ; z++)
{
for(j=10 ; j<=9+Word[z][19]; j++)
{
value = Word[z][j];
Word[z][j] = '\0';
if (value >= 97 && value<=122)
{ value = value - 32; }
else if (value >=67 && value<=90)
{ value = value + 32; }
printf("%c", value);
}
for(j=1; j<=Word[z][19]; j++)
{
value = Word[z][j];
if (value >= 97 && value<=122)
{ value = value - 32; }
else if (value >=67 && value<=90)
{ value = value + 32; }
printf("%c", value);
}
putchar('\n');
}
printf("\n");
printf("Sorted Input: \n");
printf("\n");
}