Pointer Question

This is a discussion on Pointer Question within the C Programming forums, part of the General Programming Boards category; I am trying to write a program that when you input a line of text it converts it to uppercase ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    2

    Pointer Question

    I am trying to write a program that when you input a line of text it converts it to uppercase and then lowercase. I can convert it to uppercase no problem using a while statement (required) however it doesn't move on the next while statement. Like it doesn't set the pointer back to the text that is input.

    Any help?
    Code:
    printf ("\nEnter a line of text:\n");
    gets(text_ptr);
    
    printf ("\nThe line of text in uppercase is:\n");
    
    while (*text_ptr != '\0')
    putchar ( toupper (*text_ptr++) ); /* post-increment */
    
    printf ("\n");
    
    printf ("\nThe line of text in lowercase is:\n");
    
    while (*text_ptr != '\0')
    
    putchar ( tolower (*text_ptr++) ); /* post-increment */
    Last edited by lascivious; 03-22-2009 at 12:49 PM.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    use CODE tags when you post code
    see here


    Quote Originally Posted by lascivious
    Like it doesn't set the pointer back to the text that is input.
    If by "it" you mean your program, that is correct, it does not set the pointer back. You might want to try something like this:
    Code:
    char input[256]; // or whatever
    char *ptr=input;
    while(ptr[0] != '\0') ptr++;
    // ptr is now at end of input
    ptr=input;
    //ptr is now set back to the beginning of input
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,021
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    2
    Worked perfectly!! Thanks a million!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 05:23 AM
  2. Easy pointer question
    By Edo in forum C++ Programming
    Replies: 3
    Last Post: 01-19-2009, 10:54 AM
  3. char pointer to pointer question
    By Salt Shaker in forum C Programming
    Replies: 3
    Last Post: 01-10-2009, 11:59 AM
  4. Pointer question
    By rakan in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2006, 02:23 AM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21