Like Tree4Likes

character converter

This is a discussion on character converter within the C Programming forums, part of the General Programming Boards category; Why this program doesn't convert the character to number? http://prntscr.com/vo2v4...

  1. #31
    Registered User
    Join Date
    Dec 2012
    Posts
    54
    Why this program doesn't convert the character to number?

    http://prntscr.com/vo2v4
    Last edited by Sotiris Kaniras; 03-09-2013 at 02:32 PM.

  2. #32
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675
    Always post your code in code tags. I can not even copy paste.

    You are doing this
    Code:
    if(((j=strcmp(..))) ==0)
    {..
    Ok so you are calling strcmp and you assign the result to j. Then you suppose that j is being compared with zero. I do not think so.
    What is being done is that you check if an assignment is equal to zero.
    Whatever is different from zero is considered to be true. If it is zero, is it false.
    So, the assignment is done inside the parenthesis and this results to true. Then you compare, always, if true is equal with zero(false).
    I think you know how to fix this. If not, I am going to tell Takis about it!! haha :P
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #33
    Registered User
    Join Date
    Dec 2012
    Posts
    54
    What's exactly the lldb problem?

  4. #34
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675
    Quote Originally Posted by Sotiris Kaniras View Post
    What's exactly the lldb problem?
    Has this question something to do with the logical error I spotted for you at the previous post?
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  5. #35
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,625
    Quote Originally Posted by Sotiris Kaniras View Post
    Why this program doesn't convert the character to number?

    Screenshot by Lightshot
    Well, I do not think there is an issue with the actual comparison.

    Quote Originally Posted by man 3 fgets
    fgets() reads in at most one less than size characters from stream and stores them into the buffer pointed to by s. Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer. A terminating null byte (aq\0aq) is stored after the last character in the buffer.
    Thus input is actually, say, "K\n" and not just "K", so it would not match any of the choices. There is also the matter of strcmp being case sensitive...

    http://faq.cprogramming.com/cgi-bin/...&id=1043284385

    I think you should stick to the idea that I gave you.

    You are going to have a problem regardless if you expect the code to validate the 4 part of e4, though. You need to think about that more.
    Last edited by whiteflags; 03-10-2013 at 01:42 PM.

  6. #36
    Registered User
    Join Date
    Mar 2012
    Location
    the c - side
    Posts
    235
    Quote Originally Posted by laserlight View Post
    Perhaps because the letters of the English alphabet are not guaranteed to be contiguous in value.
    The critical thing is that "HAL" will still increment to "IBM" even with EBCDIC.
    stahta01 and laserlight like this.

  7. #37
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,625
    Quote Originally Posted by gemera View Post
    The critical thing is that "HAL" will still increment to "IBM" even with EBCDIC.
    I do not always promise to dole out optimized solutions to problems, interesting though they may be.

  8. #38
    Registered User
    Join Date
    Mar 2012
    Location
    the c - side
    Posts
    235
    Interesting is good.

  9. #39
    Registered User
    Join Date
    Mar 2012
    Location
    the c - side
    Posts
    235
    btw just to pre-empt the inevitable. I only guarantee my posts here will occasionally appear to be written by someone with an IQ higher than 30.

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with hex to dec converter ??
    By XWR-AiA in forum C++ Programming
    Replies: 4
    Last Post: 04-17-2010, 06:23 PM
  2. CD to MP3 Converter
    By Dark_Phoenix in forum Tech Board
    Replies: 5
    Last Post: 12-14-2006, 02:34 PM
  3. Key Converter
    By Insenic in forum C Programming
    Replies: 5
    Last Post: 02-02-2006, 11:17 PM
  4. Help with Error - Binary to Character Converter
    By dvldrmmr in forum C++ Programming
    Replies: 7
    Last Post: 04-30-2004, 01:21 PM
  5. c to c++ converter
    By kashifk in forum C Programming
    Replies: 1
    Last Post: 04-01-2003, 04:38 PM

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