Help! C program w/Pointer Notation to Convert Text

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2005
Posts: 5
Reputation: tippytoe is an unknown quantity at this point 
Solved Threads: 0
tippytoe tippytoe is offline Offline
Newbie Poster

Help! C program w/Pointer Notation to Convert Text

 
0
  #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!!!!!

  1.  
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <ctype.h>
  5.  
  6.  
  7. void main(void)
  8. {
  9.  
  10. /* Declare variables*/
  11.  
  12. char text[70], *text_ptr;
  13. int i;
  14.  
  15. text_ptr = text;
  16.  
  17. /* Prompt user for line of text*/
  18.  
  19. printf ("\nEnter a line of text (up to 69 characters):\n");
  20. gets(text);
  21.  
  22.  
  23. /* Convert and output the text in uppercase characters.*/
  24.  
  25. printf ("\nThe line of text in uppercase is:\n");
  26.  
  27. i = 0;
  28. while ( text[i] != '\0')
  29. putchar( toupper[*text_ptr]++]) );
  30.  
  31. /*Convert and output the text in lowercase characters. */
  32.  
  33. printf ("\n\nThe line of text in lowercase is:\n");
  34.  
  35. i = 0;
  36. while ( text[*text_ptr] != '\0')
  37. putchar( tolower(text[(*text_ptr)++]) );
  38.  
  39. getch();
  40.  
  41.  
  42. } // end main
Last edited by Dave Sinkula; Apr 30th, 2006 at 7:05 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
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: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

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

 
0
  #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
  1. #include <stdio.h>
  2. int main ( ) {
  3. char test[] = "this is a test\n";
  4. char *p;
  5. int i;
  6. for ( i = 0 ; test[i] != '\0'; i++ ) putchar(test[i]);
  7. for ( p = test ; *p != '\0'; p++ ) putchar(*p);
  8. return 0;
  9. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC