RSS Forums RSS

Help! C program w/Pointer Notation to Convert Text

Please support our C advertiser: Programming Forums
Reply
Posts: 5
Reputation: tippytoe is an unknown quantity at this point 
Solved Threads: 0
tippytoe tippytoe is offline Offline
Newbie Poster

Help Help! C program w/Pointer Notation to Convert Text

  #1  
Apr 30th, 2006
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
Last edited by Dave Sinkula : Apr 30th, 2006 at 6:05 pm.
AddThis Social Bookmark Button
Reply With Quote  
Posts: 5,123
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 633
Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Help! C program w/Pointer Notation to Convert Text

  #2  
May 1st, 2006
> void main(void)
http://faq.cprogramming.com/cgi-bin/...&id=1043284376

> gets(text);
http://faq.cprogramming.com/cgi-bin/...&id=1043284351

Here's a little program to show the same thing using arrays and pointers
#include <stdio.h>
int main ( ) {
  char test[] = "this is a test\n";
  char *p;
  int i;
  for ( i = 0 ; test[i] != '\0'; i++ ) putchar(test[i]);
  for ( p = test ; *p != '\0'; p++ ) putchar(*p);
  return 0;
}
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 2443 | Replies: 1 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:17 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC