simple structure/linked list question

This is a discussion on simple structure/linked list question within the C Programming forums, part of the General Programming Boards category; Code: switch (input[0]) { case ('a'): case ('A'): add_to_list(); break; case ('d'): case ('D'): delete_from_list(); break; case ('p'): case ('P'): ...

  1. #16
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Code:
    switch (input[0]) {
                case ('a'):
                case ('A'):
                    add_to_list();
                    break;
                case ('d'):
                case ('D'):
                    delete_from_list();
                    break;
                case ('p'):
                case ('P'):
                    print_name();
                    break;
                case ('l'):
                case ('L'):
                    list_names();
                    break;
                case ('q'):
                case ('Q'):
                    free_list();
                    return (0);
                default:
                    printf ("Unknown command\n"); 
            }
    You should look into tolower(), which is in <ctype.h>. It converts a character to lowercase. You could change the above code to

    Code:
    switch (tolower(input[0])) {
                case ('a'):
                    add_to_list();
                    break;
                case ('d'):
                    delete_from_list();
                    break;
                case ('p'):
                    print_name();
                    break;
                case ('l'):
                     list_names();
                    break;
                case ('q'):
                     free_list();
                    return (0);
                default:
                    printf ("Unknown command\n"); 
            }
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  2. #17
    Hopeless
    Join Date
    Jul 2005
    Location
    Bay Area, CA
    Posts
    25
    thanks for the tip, i will definately use that next time to help reduce my lines. thanks again guys!!

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. linked list question
    By brb9412 in forum C Programming
    Replies: 16
    Last Post: 01-04-2009, 04:05 PM
  2. Pleas take a look & give a critique
    By sh3rpa in forum C++ Programming
    Replies: 14
    Last Post: 10-19-2007, 11:01 PM
  3. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 09:55 PM
  4. Simple list code
    By JimpsEd in forum C Programming
    Replies: 1
    Last Post: 05-24-2006, 03:01 PM
  5. linked list stack question
    By Drew in forum C++ Programming
    Replies: 2
    Last Post: 09-11-2003, 06:05 AM

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