Thread: integer and char, convert?

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    5

    integer and char, convert?

    Maybe this is a simple question, maybe it can't be done, I don't know

    I've got a simple menu. The user should be able to input either a integer, to go back to the previous menu, or input a filename, which makes a mp3file to be played. How should this be done?

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    75
    The best way to deal with this is to accept the input as a string and call the following function

    I also assume that your filename shouldn't be allowed to have spaces in it

    Code:
    #include <ctype.h> // put at the top
    
    // returns true if the string should be used as a mp3filename
    bool TranslateInput( const char* input )
    {
        for (int i = 0; input[i] != 0; i++)
             if ( !isalpha(input[i]) || !ispunct(input[i]) )
                  return false;
        return true;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  3. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM