Yeah I know about using gets and my style of using main, but its what my professor wants us to use for some reason. Its an introductory course so I think hes just trying to keep it simple for now, although I feel it could create bad habits.
Anyways I revised my code and I think I'm doing the entire process correctly using pointers as my professor had assigned.
Heres the new code:
Code:
#include <stdio.h>
#include <ctype.h>
main()
{
/* Variable declarations */
char text[26];
char *textPtr;
/* Prompt user for line of text */
printf ("\nEnter a line of text (up to 25 characters):\n");
gets(text);
textPtr = text; /* point textPtr to text */
/* Convert and output the text in uppercase characters */
printf ("\nThe line of text in uppercase is:\n");
/* Loop to convert to uppercase */
while ( *textPtr )
{
*textPtr = toupper(*textPtr);
textPtr++;
} /* end while */
/* Output uppercase line of text */
printf("%s\n", text);
textPtr = text; /* Convert textPtr back to original text */
/* Convert and output the text in lowercase characters */
printf ("\nThe line of text in lowercase is:\n");
/* Loop to convert to lowercase */
while ( *textPtr )
{
*textPtr = tolower(*textPtr);
textPtr++;
} /* end while */
/* Output lowercase line of text */
printf("%s\n", text);
} /* end main */