Thread: Question about something found on this site

  1. #1
    Registered User Dogmasur's Avatar
    Join Date
    Jul 2008
    Posts
    72

    Question about something found on this site

    I am still a neophyte in the world of programming and am working on writing a program that accepts a string from the user and then returns that string in three different methods:

    1) all uppercase
    2) all lowercase
    3) first letter of each word in uppercase

    This "assignment", if you will, was suggested to me by members of the site on the forum. It's helping me to learn to write functions. Also, I am not allowed to use string.h.

    I was perusing the site for technical information about converting an entire string to uppercase or lowercase and found this:

    Code:
    #include <stdio.h>
    #include <ctype.h>
    
    int main ( void )
    {
        char hello[] = "Hello World";
        char *p;
    
        printf("Before conversion:  %s\n", hello);
    
        for ( p = hello; *p != '\0'; ++p)
        {
              *p = tolower (*p);
              ++p;
         }
    
         printf("After conversion:  %s\n", hello);
    
         return 0;
    }
    My question is, won't this skip every other letter in the string? Should the incremental p used inside the body of the for loop be discarded as it will be incremented on the for line anyway?
    "The art of living is more like wrestling than dancing." - Marcus Aurelius

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Yes, you are correct - the program is in error.
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User Dogmasur's Avatar
    Join Date
    Jul 2008
    Posts
    72
    Okay, thank you. I thought I was having a brain freeze for a minute.
    "The art of living is more like wrestling than dancing." - Marcus Aurelius

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Symbol file not found for *.ko
    By yanglei_fage in forum Linux Programming
    Replies: 3
    Last Post: 03-30-2009, 08:48 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. another exercise question
    By luigi40 in forum C# Programming
    Replies: 3
    Last Post: 11-28-2005, 03:52 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Simple Question
    By John22 in forum C Programming
    Replies: 3
    Last Post: 12-14-2002, 10:41 AM