Thread: Help with writing a function

  1. #16
    ~- Y u n a -~ beely's Avatar
    Join Date
    Dec 2001
    Posts
    291
    okay, let make some example between 2 statements to save ppl's name :

    [1] scanf ("%[^\n]", variable);

    and

    [2] getchar (variable);

    ----

    so what's a deal between 2 of them? some of ppl said using scanf concept is more faster than the getchar.

    in my mind, assume that user entered the input name as "rock rolly", so the scanf should be scan every char of the variable and store into the variable until it meet the newline command ('\n').

    compare this ...

    getchar could take the whole chars of the variable and directly save it to the variable (it don't care anythings in it, eg : blank space, special char ...)

    so, how's the conclusion?

  2. #17
    Registered User
    Join Date
    Nov 2002
    Posts
    157
    Originally posted by quzah
    Furthermore, do you really think scanning a text file to count newlines is a time critical application? It's not like it's dosing medicine in a hospital or something.

    Quzah.
    well, i was suggesting this because we all should be striving for the best and fastest possible code.

  3. #18
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by stallion
    well, i was suggesting this because we all should be striving for the best and fastest possible code.
    nope nope nope nope nope. my favorite book on C explains a very logical rationale: above all make your code easy to read, easy to maintain, logical, well orgainized, well commented. only sacrifice that in extreme cases of critical loops that are repeated 2502480438340438034348 times per second or similar. the reasoning behind this is, in part:
    1. through various black magic cleanly written code can often run a bit faster than hacked-up crap for no clear reason at all (really).
    2. the 20/80 theory that 20% of your code takes up 80% of your time, so only making sacrifices in readability and maintainability in that 20% will optimize things all you need.
    hello, internet!

  4. #19
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by moi
    nope nope nope nope nope. my favorite book on C explains a very logical rationale: above all make your code easy to read, easy to maintain, logical, well orgainized, well commented. only sacrifice that in extreme cases of critical loops that are repeated 2502480438340438034348 times per second or similar. the reasoning behind
    I couldn't agree more. Readability is the key. No one wants to read fugly code. Which is why when I "do peoples homework for them", it's macroed to hell and back and is a nightmare to read...

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #20
    Registered User
    Join Date
    Nov 2002
    Posts
    157
    yes, i see what you mean. i also agree, after reading your arguments.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM
  5. Replies: 3
    Last Post: 03-04-2005, 02:46 PM