Uppercase & Lowercase

This is a discussion on Uppercase & Lowercase within the C Programming forums, part of the General Programming Boards category; How can I modify the codes to be able to see the outputs 1-lowercase and 2-Uppercase? Code: #include <stdio.h> #include ...

  1. #1
    Dennis
    Guest

    Angry Uppercase & Lowercase

    How can I modify the codes to be able to see the outputs 1-lowercase and 2-Uppercase?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    
    
    int main(int argc, char **argv)
    {
      int (*convcase[2])(int) = {toupper, tolower};
      int func;
      int result = EXIT_SUCCESS;
    
      int ch;
    
      if(argc > 0)
      {
        if(toupper((unsigned char)argv[0][0]) == 'U')
        {
          func = 0;
        }
        else
        {
          func = 1;
        }
    
        while((ch = getchar()) != EOF)
        {
          ch = (*convcase[func])((unsigned char)ch);
          putchar(ch);
        }
      }
      else
      {
        fprintf(stderr, "Unknown name. Can't decide what to do.\n");
        result = EXIT_FAILURE;
      }
    
      return result;
    }


    &#91;code]&#91;/code]tagged by Salem

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,641
    Too many brackets. "else" cannot follow "while". And you won't get an EOF from a carriage return Use '\n' instead. Fix that and it will work fine.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  3. #3
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Code:
    if(toupper((unsigned char)argv[0][0]) == 'U')
    argv[0] is the name of your program
    the first argument is argv[1]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Counting uppercase and lowercase letters in a text
    By Tintu in forum C Programming
    Replies: 2
    Last Post: 02-06-2008, 09:15 PM
  2. how to detect a lowercase or uppercase char?
    By Axel in forum C Programming
    Replies: 5
    Last Post: 09-04-2005, 12:28 PM
  3. Uppercase and lowercase
    By StarOrbs in forum C++ Programming
    Replies: 4
    Last Post: 03-09-2005, 03:18 PM
  4. Replies: 14
    Last Post: 06-06-2004, 03:51 PM
  5. C++ newbie..convert string from lowercase to uppercase
    By wireless in forum C++ Programming
    Replies: 5
    Last Post: 02-25-2002, 07:49 PM

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