to get more knowledge in 'c'

Discussion in 'C Programming' started by anand devarajan, Sep 24, 2006.

  1. hi friends,
    i need some one to frame me questions for to write programs,it
    might be simple ones like prime no. prg but i need this type of
    coaching for to develop my programming knowledge
    anand devarajan, Sep 24, 2006
    #1
    1. Advertising

  2. anand devarajan wrote:

    > hi friends,
    > i need some one to frame me questions for to write programs,it
    > might be simple ones like prime no. prg but i need this type of
    > coaching for to develop my programming knowledge


    Ok , write a programme which eliminates the blanks from
    the end of every line in its standard input and prints the
    result on standard output.
    Spiros Bousbouras, Sep 24, 2006
    #2
    1. Advertising

  3. Spiros Bousbouras wrote:

    > anand devarajan wrote:
    >
    > > hi friends,
    > > i need some one to frame me questions for to write programs,it
    > > might be simple ones like prime no. prg but i need this type of
    > > coaching for to develop my programming knowledge

    >
    > Ok , write a programme which eliminates the blanks from
    > the end of every line in its standard input and prints the
    > result on standard output.


    Oh yeah , to make it more interesting the programme should
    use a constant amount of memory regardless of how large
    the lines are.
    Spiros Bousbouras, Sep 24, 2006
    #3
  4. anand devarajan

    Ico Guest

    anand devarajan <> wrote:
    > hi friends,
    > i need some one to frame me questions for to write programs,it
    > might be simple ones like prime no. prg but i need this type of
    > coaching for to develop my programming knowledge


    Here is one for you: write a program that adds proper capitalization and
    interpunction to a usenet message.
    Ico, Sep 24, 2006
    #4
  5. anand devarajan

    Simon Biber Guest

    Spiros Bousbouras wrote:
    > anand devarajan wrote:
    >
    >> hi friends,
    >> i need some one to frame me questions for to write programs,it
    >> might be simple ones like prime no. prg but i need this type of
    >> coaching for to develop my programming knowledge

    >
    > Ok , write a programme which eliminates the blanks from
    > the end of every line in its standard input and prints the
    > result on standard output.


    Good idea.

    There are some idioms in C which you can re-use over and over every time
    you see a problem like this.

    Here is one that copies each character from standard input to standard
    output:

    First you define an int variable to hold the result of getchar. That
    will be a value from 0 to UCHAR_MAX if successful, and a negative value
    called EOF if unsuccessful. Don't try to use a char variable for this.

    int ch;

    Then you start a loop. Each time through the loop, there is a complex
    expression that is evaluated. First, the getchar function is called and
    the result is stored in ch. Then the result is compared against the
    constant EOF. The loop continues while the value returned is not EOF.

    while( (ch = getchar()) != EOF )

    {

    /* Inside the loop, for each character, you must output it */

    putchar(ch);

    }

    And make sure to remember to end your main function with
    return 0;

    Here's the complete program:

    #include <stdio.h>

    int main(void)
    {
    int ch;
    while((ch = getchar()) != EOF)
    {
    putchar(ch);
    }
    return 0;
    }

    Now think about how to modify this basic copying program, to remove any
    spaces from the end of lines.

    You can test whether you have read a space, a newline character, or some
    other type like this:

    if(ch == ' ')
    {
    /* do something */
    }
    else if(ch == '\n')
    {
    /* do something else */
    }
    else
    {
    /* do something different */
    }

    There is a tricky part though, as you will be reading the space
    characters before the newline comes in. You don't know how many space
    characters will come in. You might read 10 of them and then find there
    is a non-space character. In that case the 10 spaces you read were not
    at the end of the line but in the middle, and they must be preserved in
    the output.

    I would introduce a new variable, to keep track of how many spaces have
    been read. When I read a space, I will just increment the counter, but
    not actually output anything. When I read a newline, I will reset the
    counter to zero but not output anything except the newline. But when I
    read something that is neither a space nor a newline, I must print some
    spaces, according to the current value of the counter. I will then reset
    the counter and print the actual character that was read.

    Can you implement this in C? You will need to add one or two new
    variables and another loop inside.

    Or perhaps you can think of an even better way to solve the problem?

    --
    Simon.
    Simon Biber, Sep 24, 2006
    #5
  6. anand devarajan

    CBFalconer Guest

    Spiros Bousbouras wrote:
    > Spiros Bousbouras wrote:
    >> anand devarajan wrote:
    >>
    >>> i need some one to frame me questions for to write programs,it
    >>> might be simple ones like prime no. prg but i need this type of
    >>> coaching for to develop my programming knowledge

    >>
    >> Ok , write a programme which eliminates the blanks from
    >> the end of every line in its standard input and prints the
    >> result on standard output.

    >
    > Oh yeah , to make it more interesting the programme should
    > use a constant amount of memory regardless of how large
    > the lines are.


    And just to make it more elegant, handle embedded tabs, assuming
    tabstops every 8th position.

    If anand doesn't learn to stop top-posting he will stop getting any
    help here.

    --
    Some informative links:
    <news:news.announce.newusers
    <http://www.geocities.com/nnqweb/>
    <http://www.catb.org/~esr/faqs/smart-questions.html>
    <http://www.caliburn.nl/topposting.html>
    <http://www.netmeister.org/news/learn2quote.html>
    <http://cfaj.freeshell.org/google/>
    CBFalconer, Sep 24, 2006
    #6
  7. anand devarajan posted:

    > hi friends,
    > i need some one to frame me questions for to write programs,it
    > might be simple ones like prime no. prg but i need this type of
    > coaching for to develop my programming knowledge


    How about this:

    Write a function with the following signature:

    void FindReplace(char *,char const *,char const *)

    The first argument is a pointer to a modifiable null-terminated string
    which is to be processed and altered. The second argument is a pointer to a
    null-terminated string indicating which characters are to be searched for.
    The third argument is a pointer to a null-terminated string specifying the
    replacement characters. So for instance, if the function were invoked as
    follows:

    char str[] = "The man walked into the bar."

    FindReplace(str,"aeiou","vwxyz");

    , then "str" will be changed to: "Thw mvn wvlkwd xnty thw bvr."

    --

    Frederick Gotham
    Frederick Gotham, Sep 24, 2006
    #7
  8. anand devarajan

    Joe Wright Guest

    Ico wrote:
    > anand devarajan <> wrote:
    >> hi friends,
    >> i need some one to frame me questions for to write programs,it
    >> might be simple ones like prime no. prg but i need this type of
    >> coaching for to develop my programming knowledge

    >
    > Here is one for you: write a program that adds proper capitalization and
    > interpunction to a usenet message.
    >

    And add a spell checker. 'interpunction'?

    --
    Joe Wright
    "Everything should be made as simple as possible, but not simpler."
    --- Albert Einstein ---
    Joe Wright, Sep 25, 2006
    #8
  9. anand devarajan

    CBFalconer Guest

    Joe Wright wrote:
    > Ico wrote:
    >> anand devarajan <> wrote:
    >>>
    >>> i need some one to frame me questions for to write programs,it
    >>> might be simple ones like prime no. prg but i need this type of
    >>> coaching for to develop my programming knowledge

    >>
    >> Here is one for you: write a program that adds proper
    >> capitalization and interpunction to a usenet message.

    >
    > And add a spell checker. 'interpunction'?


    No problem. Interpunction refers to the act of transferring
    punctures between pneumatic tires. :) This is different from
    'extreme interpunction', which has to do with the final rites for
    interpreters.

    --
    Some informative links:
    <news:news.announce.newusers
    <http://www.geocities.com/nnqweb/>
    <http://www.catb.org/~esr/faqs/smart-questions.html>
    <http://www.caliburn.nl/topposting.html>
    <http://www.netmeister.org/news/learn2quote.html>
    <http://cfaj.freeshell.org/google/>
    CBFalconer, Sep 25, 2006
    #9
  10. In article <>,
    Joe Wright <> wrote:

    >> Here is one for you: write a program that adds proper capitalization and
    >> interpunction to a usenet message.


    >And add a spell checker. 'interpunction'?


    "Interpunction" is a perfectly cromulent word.

    -- Richard
    Richard Tobin, Sep 25, 2006
    #10
  11. Joe Wright said:

    > Ico wrote:
    >> anand devarajan <> wrote:
    >>> hi friends,
    >>> i need some one to frame me questions for to write programs,it
    >>> might be simple ones like prime no. prg but i need this type of
    >>> coaching for to develop my programming knowledge

    >>
    >> Here is one for you: write a program that adds proper capitalization and
    >> interpunction to a usenet message.
    >>

    > And add a spell checker. 'interpunction'?


    You need to get a new glarkurettor for your vocabulator. :)

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
    Richard Heathfield, Sep 25, 2006
    #11
  12. anand devarajan

    Chris Torek Guest

    >>> Here is one for you: write a program that adds proper capitalization and
    >>> interpunction to a usenet message.


    >In article <>,
    >Joe Wright <> wrote:
    >>And add a spell checker. 'interpunction'?


    Chuck Falconer wrote (in a message whose ID I failed to capture):
    >Interpunction refers to the act of transferring
    >punctures between pneumatic tires. :)


    In article <ef7alc$nfd$>
    Richard Tobin <> wrote:
    >"Interpunction" is a perfectly cromulent word.


    "Cromulent" is not (yet?) an accepted word in most dictionaries
    (see <http://www.urbandictionary.com/define.php?term=Cromulent>),
    but "interpunction" today might be the act of inserting the
    interpunct, a sort of center decimal point ("&middot;" in HTML-ese),
    that was used in Latin. See <http://en.wikipedia.org/wiki/Interpunct>.
    This word-separating character was apparently originally called an
    "interpunction", so it is now actually valid as both a noun and a verb.
    --
    In-Real-Life: Chris Torek, Wind River Systems
    Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
    email: forget about it http://web.torek.net/torek/index.html
    Reading email is like searching for food in the garbage, thanks to spammers.
    Chris Torek, Sep 25, 2006
    #12
  13. anand devarajan

    Ico Guest

    Joe Wright <> wrote:
    > Ico wrote:
    >> anand devarajan <> wrote:
    >>> hi friends,
    >>> i need some one to frame me questions for to write programs,it
    >>> might be simple ones like prime no. prg but i need this type of
    >>> coaching for to develop my programming knowledge

    >>
    >> Here is one for you: write a program that adds proper capitalization and
    >> interpunction to a usenet message.
    >>

    > And add a spell checker. 'interpunction'?


    I must admit I usually don't use spellcheckers, but I believe 'interpunction'
    is a perfectly valid word ?

    $ dict interpunction

    1 definition found

    From The Collaborative International Dictionary of English v.0.48 [gcide]:

    Interpunction \In`ter*punc"tion\, n. [L. interpunctio, fr.
    interpungere, interppunctum, to interpoint. See {Inter-}, and
    {Point}.]
    The insertion of points between words or sentences;
    [1913 Webster]

    --
    :wq
    ^X^Cy^K^X^C^C^C^C
    Ico, Sep 25, 2006
    #13
  14. anand devarajan

    Michael Mair Guest

    Ico schrieb:
    > Joe Wright <> wrote:
    >>Ico wrote:
    >>>anand devarajan <> wrote:
    >>>
    >>>>hi friends,
    >>>> i need some one to frame me questions for to write programs,it
    >>>>might be simple ones like prime no. prg but i need this type of
    >>>>coaching for to develop my programming knowledge
    >>>
    >>>Here is one for you: write a program that adds proper capitalization and
    >>>interpunction to a usenet message.

    >>
    >>And add a spell checker. 'interpunction'?

    >
    > I must admit I usually don't use spellcheckers, but I believe 'interpunction'
    > is a perfectly valid word ?
    >
    > $ dict interpunction
    >
    > 1 definition found
    >
    > From The Collaborative International Dictionary of English v.0.48 [gcide]:
    >
    > Interpunction \In`ter*punc"tion\, n. [L. interpunctio, fr.
    > interpungere, interppunctum, to interpoint. See {Inter-}, and
    > {Point}.]
    > The insertion of points between words or sentences;
    > [1913 Webster]


    FWIW:
    interpunction(Engl.) != Interpunktion(German) == punctuation(Engl.)
    Maybe this is a similar case of "false friends" for you.

    -Michael
    --
    E-Mail: Mine is an /at/ gmx /dot/ de address.
    Michael Mair, Sep 25, 2006
    #14
  15. anand devarajan

    Ico Guest

    Michael Mair <> wrote:
    > Ico schrieb:
    >> Joe Wright <> wrote:
    >>>Ico wrote:
    >>>>anand devarajan <> wrote:
    >>>>
    >>>>>hi friends,
    >>>>> i need some one to frame me questions for to write programs,it
    >>>>>might be simple ones like prime no. prg but i need this type of
    >>>>>coaching for to develop my programming knowledge
    >>>>
    >>>>Here is one for you: write a program that adds proper capitalization and
    >>>>interpunction to a usenet message.
    >>>
    >>>And add a spell checker. 'interpunction'?

    >>
    >> I must admit I usually don't use spellcheckers, but I believe 'interpunction'
    >> is a perfectly valid word ?
    >>
    >> $ dict interpunction
    >>
    >> 1 definition found
    >>
    >> From The Collaborative International Dictionary of English v.0.48 [gcide]:
    >>
    >> Interpunction \In`ter*punc"tion\, n. [L. interpunctio, fr.
    >> interpungere, interppunctum, to interpoint. See {Inter-}, and
    >> {Point}.]
    >> The insertion of points between words or sentences;
    >> [1913 Webster]

    >
    > FWIW:
    > interpunction(Engl.) != Interpunktion(German) == punctuation(Engl.)
    > Maybe this is a similar case of "false friends" for you.


    Yes, you're right. Germany is only next door here, so that's where my
    mixup came from. Punctuation it is :)


    --
    :wq
    ^X^Cy^K^X^C^C^C^C
    Ico, Sep 25, 2006
    #15
  16. anand devarajan

    Eric Sosman Guest

    [OT] Re: to get more knowledge in 'c'

    CBFalconer wrote:
    >
    > If anand doesn't learn to stop top-posting he will stop getting any
    > help here.


    While it's true that anand top-posted in his only message
    to this thread (the only one my news server sees, anyhow), I
    feel that he should be forgiven. It is, after all, no easy
    matter to avoid top-posting in a thread's first message.

    --
    Eric Sosman
    lid
    Eric Sosman, Sep 25, 2006
    #16
  17. anand devarajan

    jmcgill Guest

    Ico wrote:

    > $ dict interpunction
    >
    > 1 definition found
    >
    > From The Collaborative International Dictionary of English v.0.48 [gcide]:
    >
    > Interpunction \In`ter*punc"tion\, n. [L. interpunctio, fr.
    > interpungere, interppunctum, to interpoint. See {Inter-}, and
    > {Point}.]
    > The insertion of points between words or sentences;
    > [1913 Webster]


    It's in a 1996 Webster's as well. I like the word, because I've been
    frustrated before trying to describe it when doing various forms of text
    processing ;-)
    jmcgill, Sep 25, 2006
    #17
  18. anand devarajan

    jmcgill Guest

    Chris Torek wrote:
    >>>> Here is one for you: write a program that adds proper capitalization and
    >>>> interpunction to a usenet message.

    >
    >> In article <>,
    >> Joe Wright <> wrote:
    >>> And add a spell checker. 'interpunction'?

    >
    > Chuck Falconer wrote (in a message whose ID I failed to capture):
    >> Interpunction refers to the act of transferring
    >> punctures between pneumatic tires. :)

    >
    > In article <ef7alc$nfd$>
    > Richard Tobin <> wrote:
    >> "Interpunction" is a perfectly cromulent word.

    >
    > "Cromulent" is not (yet?) an accepted word in most dictionaries
    > but "interpunction" today might be the act of inserting the
    > interpunct, a sort of center decimal point ("&middot;" in HTML-ese),
    > that was used in Latin. See <http://en.wikipedia.org/wiki/Interpunct>.
    > This word-separating character was apparently originally called an
    > "interpunction", so it is now actually valid as both a noun and a verb.


    The word "interpunction" long predates HTML.

    The word "cromulent" is a humorous neologism from a popular animated TV
    show.
    jmcgill, Sep 25, 2006
    #18
  19. anand devarajan

    Coos Haak Guest

    Op 25 Sep 2006 10:09:34 GMT schreef Ico:

    > Michael Mair <> wrote:
    >> Ico schrieb:
    >>> Joe Wright <> wrote:
    >>>>Ico wrote:
    >>>>>anand devarajan <> wrote:
    >>>>>
    >>>>>>hi friends,
    >>>>>> i need some one to frame me questions for to write programs,it
    >>>>>>might be simple ones like prime no. prg but i need this type of
    >>>>>>coaching for to develop my programming knowledge
    >>>>>
    >>>>>Here is one for you: write a program that adds proper capitalization and
    >>>>>interpunction to a usenet message.
    >>>>
    >>>>And add a spell checker. 'interpunction'?
    >>>
    >>> I must admit I usually don't use spellcheckers, but I believe 'interpunction'
    >>> is a perfectly valid word ?
    >>>
    >>> $ dict interpunction
    >>>
    >>> 1 definition found
    >>>
    >>> From The Collaborative International Dictionary of English v.0.48 [gcide]:
    >>>
    >>> Interpunction \In`ter*punc"tion\, n. [L. interpunctio, fr.
    >>> interpungere, interppunctum, to interpoint. See {Inter-}, and
    >>> {Point}.]
    >>> The insertion of points between words or sentences;
    >>> [1913 Webster]

    >>
    >> FWIW:
    >> interpunction(Engl.) != Interpunktion(German) == punctuation(Engl.)
    >> Maybe this is a similar case of "false friends" for you.

    >
    > Yes, you're right. Germany is only next door here, so that's where my
    > mixup came from. Punctuation it is :)


    But in Dutch it's interpunctie again :)
    No word like punctuatie.
    --
    Coos
    Coos Haak, Sep 25, 2006
    #19
  20. anand devarajan

    Mabden Guest

    Re: [OT] Re: to get more knowledge in 'c'

    I agree! ;-)

    "Eric Sosman" <> wrote in message
    news:...
    > CBFalconer wrote:
    > >
    > > If anand doesn't learn to stop top-posting he will stop getting any
    > > help here.

    >
    > While it's true that anand top-posted in his only message
    > to this thread (the only one my news server sees, anyhow), I
    > feel that he should be forgiven. It is, after all, no easy
    > matter to avoid top-posting in a thread's first message.
    Mabden, Oct 2, 2006
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sean
    Replies:
    4
    Views:
    334
    Alvin Bruney [MVP]
    Mar 2, 2004
  2. Michael
    Replies:
    4
    Views:
    410
    Matt Hammond
    Jun 26, 2006
  3. Replies:
    0
    Views:
    345
  4. Replies:
    2
    Views:
    285
  5. Robert Klemme

    With a Ruby Yell: more, more more!

    Robert Klemme, Sep 28, 2005, in forum: Ruby
    Replies:
    5
    Views:
    216
    Jeff Wood
    Sep 29, 2005
Loading...

Share This Page