Thread: Uppercase & Lowercase

  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,708
    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:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  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, 10: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, 04: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, 08:49 PM