Thread: help with c program: binary to ascii program

  1. #16
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by bigmac(rexdale) View Post
    does it matter the placement, like if i put a case 'R': before the case 0: and 1:?

    also, how should i check if the next two are TP? this is where im stuck.
    It doesn't matter where, just somewhere.

    You've got a big pile of characters, don't you? Look at your switch statement: which one are you checking now? If that one is R, what needs to be T, and what needs to be P?

  2. #17
    Registered User
    Join Date
    Oct 2007
    Posts
    118
    Quote Originally Posted by tabstop View Post
    It doesn't matter where, just somewhere.

    You've got a big pile of characters, don't you? Look at your switch statement: which one are you checking now? If that one is R, what needs to be T, and what needs to be P?
    well if one is R, what needs to be T is the following character and what needs to be P is the next following character.

  3. #18
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by bigmac(rexdale) View Post
    well if one is R, what needs to be T is the following character and what needs to be P is the next following character.
    And what is the "one" that we're checking: we're checking core[i] (since that's the argument to our switch). So if core[i] == 'R', we need ________ == 'T' and ________ == 'P'. Fill in the blanks and you're done.

  4. #19
    Registered User
    Join Date
    Oct 2007
    Posts
    118
    core[i] == 'T' and same for P??

  5. #20
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    No, core[i] == 'R'. The next one needs to be 'T'.

  6. #21
    Registered User
    Join Date
    Oct 2007
    Posts
    118
    oh, do you mean, core[i++]?

    Code:
    case 'R':
             i++; 
             if(core[i]=='P'){ 
               i++;
             }
             if(core[i]=='T'){
               printf("RPT");
             }
    seems to work now, but i need to see if the next character is a digit after the T
    Last edited by bigmac(rexdale); 01-14-2008 at 04:27 PM.

  7. #22
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by bigmac(rexdale) View Post
    oh, do you mean, core[i++]?

    Code:
    case 'R':
             i++; 
             if(core[i]=='P'){ 
               i++;
             }
             if(core[i]=='T'){
               printf("RPT");
             }
    seems to work now, but i need to see if the next character is a digit after the T
    Well, wouldn't that digit now be in core[++i]? The hairy bit would be if you would need to check for two-digit (or three-digit) etc. numbers -- in other words, do you know when to stop reading an RPT code and start reading 1s and 0s again?

  8. #23
    Registered User
    Join Date
    Oct 2007
    Posts
    118
    thats what i need to find out, if its a digit and how long the digit is. (the number that comes after RPT)

    for the RTP, i have to use the 8 1's/0's that come before RTP, so a code like this 01010101 RPT2 would mean i have to use the 8 1's 0's (01010101) before RPT and do it 2 times. but the problem is i also have to be able to find the 8 1's 0's before the RPT with other characters like A or b or 9.

  9. #24
    Registered User
    Join Date
    Oct 2007
    Posts
    118
    ^^can someone help, been trying ever since and still i cant get it

  10. #25
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Please post your current code.

  11. #26
    Registered User
    Join Date
    Jan 2008
    Location
    Ontario
    Posts
    2
    to check if a character is between 1 and 9 you would have to write;
    core[i + 3] >= '1' && core[i + 3] <= '9'

    and you are at least detecting at that point whether the core array is holding a character from 1 to 9

  12. #27
    Registered User
    Join Date
    Jan 2008
    Location
    Ontario
    Posts
    2
    at the certain point in the array

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Convert to ASCII program almost working
    By ggraz in forum C Programming
    Replies: 8
    Last Post: 09-17-2008, 06:54 PM
  2. binary search program
    By galmca in forum C Programming
    Replies: 5
    Last Post: 01-25-2005, 12:00 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. ASCII -> Binary
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 11-13-2001, 05:51 AM
  5. Replies: 4
    Last Post: 10-16-2001, 02:00 PM