Decoding

This is a discussion on Decoding within the C Programming forums, part of the General Programming Boards category; this function should find out the first element of array is an interger or a character, then store that element ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    32

    Decoding

    this function should find out the first element of array is an interger or a character, then store that element to character named C. but it does not do that..
    What can be wrong?

    this is my input function
    Code:
    gets(userinput);
    decodeinput(userinput);
    here's decoding function
    Code:
    void decodeinput(char input[100])
    {
    
    int i;
    char input3[100];
    
    for(i=0; i<100; i++)
    input3[i] = input[i];
    
    strupr(input3); /* Make command to upper case */
    if('0' < input[0]  <'9')
    num = input[0];
    else if ('A' < input3[0] < 'Z')
    {   
    	c = input3[0];
        printf("%c", c);
        num = 0;
    }
    Last edited by jk81; 11-12-2002 at 09:44 PM.

  2. #2
    booyakasha
    Join Date
    Nov 2002
    Posts
    208
    There are a lot of problems with the code

    Two of the problems are

    1) the if condition should be

    if('0' < input[0] && input[0] <'9')

    2) if you put a char into an int , like int x = '6', the value 6 will not be put in the int , instead the ASCII value will be put in

    for example

    int i = '2';
    cout << i;

    prints 50

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    14

    Re: Decoding

    Code:
    for(i=0; i<100; i++)
    input3[i] = input[i];
    use strcpy() to copy input to input3

    syntax : strcpy(input3,input);

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by beege31337
    There are a lot of problems with the code
    I couldn't agree more. The first problem however, is with the very first line. I'll paste it in here, you see if you can spot it:
    gets(userinput);
    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    32
    Code:
    char userinput[100];
    
    gets(userinput);
    if gets(userinput) is wrong, then which function should I use?
    scanf?
    getch?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with decoding program...
    By porsche911nfs in forum C++ Programming
    Replies: 18
    Last Post: 04-10-2009, 12:21 AM
  2. Help decoding base_64+GZipped string
    By Zeokat in forum C# Programming
    Replies: 3
    Last Post: 12-05-2008, 04:06 PM
  3. Decoding applications?
    By Hybird in forum C++ Programming
    Replies: 2
    Last Post: 11-13-2005, 06:19 AM
  4. Decoding & Encoding the sound?!?
    By waldis in forum C++ Programming
    Replies: 2
    Last Post: 10-20-2002, 06:41 PM
  5. Decoding in arrays
    By stimpyzu in forum C++ Programming
    Replies: 6
    Last Post: 04-06-2002, 12:21 PM

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