Start New Discussion within our Software Development Community

Hi - The assignment is to write a C program that prompts the user to enter a line of text up to 69 chars, then convert the text to upper and lower case. The program is required to use pointer notation, not array notation. The program needs to setup a pointer to the text array. I am having a hard time understanding pointers.. below is my code thus far which is not working (it only outputs garbage). Please HELP !! It is due very soon!!!!!

#include <stdio.h>
#include <conio.h>
#include <ctype.h>
 

void main(void)
{
 
 /* Declare variables*/
 
	char  text[70], *text_ptr;
	int   i;
 
	text_ptr = text;

 /* Prompt user for line of text*/
 
	printf ("\nEnter a line of text (up to 69 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]++]) );
 
 /*Convert and output the text in lowercase characters. */
 
	printf ("\n\nThe line of text in lowercase is:\n");
 
	i = 0;
		while ( text[*text_ptr] != '\0')  
		putchar( tolower(text[(*text_ptr)++]) );
  
	getch();
 

} // end main
This article has been dead for over six months. Start a new discussion instead.