Thread: Simple int -> char conversion failing...

  1. #1
    Join Date
    Dec 2005

    Simple int -> char conversion failing...

    I'm trying to convert an int to a char, just to see if the value entered is a alphabetic character. Here's what I have in my method:
    void FillUserArray( int userArray[], int arraySize )
        int i = 0;  //array indexer
        int j = 1;  //counter for output format
        int x;    //holders for user input
        while( i < arraySize )
            printf( "#%d: ", j );
            scanf( "%d", &x );
            userArray(i) = x; //code pasting into forum doesn't allow [ ]
            if( isalpha( (char)x ) )
                printf( "no alpha" );
            if( x < 1 || x > 47 )
                printf( "\nThe number you are entering cannot be less than one, and no greater than forty-seven.\n\n" );
            else if( HasBeenAssigned( userArray, arraySize, x, i ) == x )
                printf( "\nPlease make sure the number you are entering has not already been assigned.\n\n" );
    When scanf reads a letter into x, though, it just loops endlessly. How can I detect if the value entered is a character, and then print something if it is?

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM