| | |
Help! C program w/Pointer Notation to Convert Text
![]() |
•
•
Join Date: Oct 2005
Posts: 5
Reputation:
Solved Threads: 0
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!!!!!
C Syntax (Toggle Plain Text)
#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 7:05 pm.
> 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
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
C Syntax (Toggle Plain Text)
#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; }
![]() |
Similar Threads
- converting a text or xml file into binary format (Visual Basic 4 / 5 / 6)
- Pointers (archived tutorial) (C++)
- Help with program to convert hex to dec (Assembly)
- Pointer to a data member (C++)
- Convert binary into text/text into binary (Pascal and Delphi)
- Read in a string from a text file (C)
- Text printing is giving me trouble (C#)
- Pointers (C++)
Other Threads in the C Forum
- Previous Thread: Simplified Computer(CS): escalonamento algorithms, FCFS, SJP, Round-Robin [was: Help]
- Next Thread: bitwise operations in C
| Thread Tools | Search this Thread |
* adobe ansi api array asterisks binarysearch calculate centimeter char character cm convert copyanyfile copyimagefile copypdffile cprogramme createcopyoffile createprocess() csyntax directory feet fflush fgets file floatingpointvalidation fork frequency function givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hacking highest homework i/o inches infiniteloop interest intmain() iso keyboard kilometer km linked linkedlist linux linuxsegmentationfault list locate lowest match meter microsoft mqqueue mysql number oddnumber odf open opendocumentformat openwebfoundation owf pattern pdf performance posix power probleminc program programming pyramidusingturboccodes read recv recvblocked repetition reversing scanf scheduling segmentationfault send single socketprograming socketprogramming stack standard string suggestions systemcall unix urboc user variable voidmain() wab whythiscodecausesegmentationfault win32api windows.h






