Code:
if ( k > 64 && < 91 )
{
words[i][j]= tolower(words[i][j] );
}
else if ( k >96 && <123 );
{
words[i][j]= toupper(words[i][j] );
}
It would read better to not use hardwired numbers, and to be completely portable ctype.h provides very nice character testing functions, like: isupper, and islower.
Code:
if ( isupper(k) )
{
words[i][j]= tolower(words[i][j] );
}
else if ( islower(k) );
{
words[i][j]= toupper(words[i][j] );
}
A common mistake here:
Code:
if ( strcmp(words[j],words[j+1])>0 )
{
strcpy(swap,words[j]);
strcpy(words[j],words[j+1]);
strcpy(words[j+1],swap);
}
The 'swap' variable can not hold a string, because you declare it as char. Therefore you overwrite memory there on the stack destroying the values of 'k', 'i', 'j' and 'c'. strcpy doesn't know it is bad to write there, but 'swap' can only hold at least 1 byte.
Code:
char toupper(char let)
{
int d;
d = (int)let;
let = (char)d-32;
return let; /* All of the above statements can become: return let-32; */
}
char tolower(char let)
{
int d;
d = (int)let;
let = (char)d+32;
return let;
}
Unnecessary copying and casting. It makes only confusion in the function body.
You copy the char to an int, and then cast the int to char at the next statement.
Sometimes things can be confusingly simple. If you need to calculate 100-44, would you write 100 on another paper, then write 100 on the solution paper which already has 100 written on it, and then put 44 below 100 and do the subtraction? Think about that a bit.