Thread: Plz Help B4 I Commit Suicide

  1. #16
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Well if we are going to post solutions my version is only 6 lines!
    Code:
    int isNumber(char *s)
    {
        int dot=0,num=0,end=0;while(isspace(*s))s++;if(*s=='-'||*s=='+')s++;while(*s)
        if(isspace(*s))end=1, s++;else if(end)return 0;else if(isdigit(*s))num=1,s++; 
        else if(*s=='.')if(dot)return 0;else dot=1,s++;else return 0; return num;
    }

  2. #17
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by mike_g View Post
    Well if we are going to post solutions my version is only 6 lines!
    Code:
    int isNumber(char *s)
    {
        int dot=0,num=0,end=0;while(isspace(*s))s++;if(*s=='-'||*s=='+')s++;while(*s)
        if(isspace(*s))end=1, s++;else if(end)return 0;else if(isdigit(*s))num=1,s++; 
        else if(*s=='.')if(dot)return 0;else dot=1,s++;else return 0; return num;
    }
    First, that's not nice looking readable code - your indentation would make Elysia cry!

    If that's meant to validate a float, you are missing the E|e{+,-}{*0-9} notation.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #18
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Lol, yeah I never said it was perfect

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    That's improper, unreadable code. You could theoretically just squeeze all lines into one and claim you have a one-line function, though.
    But on a serious note, that code is worse than what 90% of the newbies post here.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Yeah I would have put it all on one line but I dident want to screw up the margins :P Hopefully my little function hasent caused too much trauma for you, lol.

  6. #21
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > But on a serious note, that code is worse than what 90% of the newbies post here.
    What do you mean? He's just a newbie with 700 posts

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  3. Poem: Suicide Note
    By KingZoolerius66 in forum A Brief History of Cprogramming.com
    Replies: 54
    Last Post: 12-31-2003, 05:39 PM
  4. Training children to commit suicide.
    By Liger86 in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 02-06-2003, 09:59 PM
  5. Suicide
    By Series X4 1.0 in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 10-17-2001, 02:26 PM