I have a simple program I am coding for my class and so far I have got the program to do what I want it to do, however I am not sure if I am using pointers as my professor had asked us to use in this program correctly.
Could someone take a look at this code and let me know if I am actually using pointers here to convert a line of text to uppercase and then lowercase?
I seem to believe that I am suppose to have an * next to text_Ptr throughout the code, however when I put the * the code does not compile correctly and gives this error "invalid type argument of `unary *'".Code:#include <stdio.h> #include <ctype.h> main() { /* Variable declarations */ char text[26]; int i; char *text_Ptr = text; /* Prompt user for line of text */ printf ("\nEnter a line of text (up to 25 characters):\n"); gets(text); /* Convert and output the text in uppercase characters */ printf ("\nThe line of text in uppercase is:\n"); i = 0; while ( text[i] != '\0') { putchar( toupper(text_Ptr[i++]) ); <--- should the text_Ptr have a * here? } /* Convert and output the text in lowercase characters */ printf ("\n\nThe line of text in lowercase is:\n"); i = 0; while ( text[i] != '\0') { putchar( tolower(text_Ptr[i++]) ); <--- should the text_Ptr have a * here? } printf ("\n"); } /* end main */
Any help is much appreciated.



LinkBack URL
About LinkBacks



