plz help to solve some problem

Discussion in 'C Programming' started by Fahad, May 27, 2005.

  1. Fahad

    Fahad Guest

    I am a newcommer in c world,
    I am making a tiny program on Mathematics.
    I have one problem if somebody enter his name, "i am able to make the
    first letter uppercase but my problem how can i make the 1st letter
    after space to be uppercase" plz help me.
    Then "how can i get the value of Sin30 degree".
    And how can I draw a Triangle or a rectangle shape.
     
    Fahad, May 27, 2005
    #1
    1. Advertising

  2. Fahad

    -berlin.de Guest

    Fahad <> wrote:
    > I am a newcommer in c world,
    > I am making a tiny program on Mathematics.
    > I have one problem if somebody enter his name, "i am able to make the
    > first letter uppercase but my problem how can i make the 1st letter
    > after space to be uppercase" plz help me.


    Iterate over the array of chars until you find a space, take the
    next char and covert it to uppercase. If you would show us some
    code you already have we might be able to give you some more
    helpful answer.

    > Then "how can i get the value of Sin30 degree".


    Use the sin() function and call it with an argument of 30 degree
    after you converted that to radians (or simply use 0.5, that
    saves a bit of CPU time;-)

    > And how can I draw a Triangle or a rectangle shape.


    There are no functions in standard C for drawing. You will need
    to use some extensions supplied for the system you are using).
    You will have to ask that in a group that is dedicated to dis-
    cussions about programming for your system.

    Regards, Jens
    --
    \ Jens Thoms Toerring ___ -berlin.de
    \__________________________ http://www.toerring.de
     
    -berlin.de, May 27, 2005
    #2
    1. Advertising

  3. Fahad

    Malcolm Guest

    "Fahad" <> wrote
    >.
    > I have one problem if somebody enter his name, "i am able to make the
    > first letter uppercase but my problem how can i make the 1st letter
    > after space to be uppercase" plz help me.
    >

    void capitalisewords(char *str)
    {
    char *ptr;
    if(isalpha(*str))
    *str = toupper(*str);
    ptr = str;
    while(ptr = strchr(ptr, ' '))
    {
    if(isalpha(*ptr))
    *ptr = toupper(*ptr);
    ptr++;
    }
    }
    >
    > Then "how can i get the value of Sin30 degree".
    >

    double degtorad(double degrees)
    {
    return degrees/360 * 2 * 3.14;
    }

    /* get sine 30 degrees */
    sin( degtorad(30) );
    >
    > And how can I draw a Triangle or a rectangle shape.
    >

    The problem is there is no standard graphical system.

    Drawing lines is surprisingly tricky, and most sytems provide basic line and
    polygon functions as standard. If you really want to know how to do it, look
    up Brasenham's algorithm.
    Once you have a line drawer, an open rectnagle or triangle is no problem.

    Drawing a filled triangle is also tricky. The normal approach is to cut it
    in half so that yiu have a flat-topped and a flat-bottomed triange, and then
    calculate start and end points for each scan line.
     
    Malcolm, May 27, 2005
    #3
  4. Fahad

    Malcolm Guest

    "Malcolm" <> wrote in message
    news:d785uj$ig3$-infra.bt.com...
    >
    > "Fahad" <> wrote
    >>.
    >> I have one problem if somebody enter his name, "i am able to make the
    >> first letter uppercase but my problem how can i make the 1st letter
    >> after space to be uppercase" plz help me.
    >>

    > void capitalisewords(char *str)
    > {
    > char *ptr;
    > if(isalpha(*str))
    > *str = toupper(*str);
    > ptr = str;
    > while(ptr = strchr(ptr, ' '))
    > {

    ptr++;
    > if(isalpha(*ptr))
    > *ptr = toupper(*ptr);

    /* > ptr++; */
    > }
    > }
    >>
    >> Then "how can i get the value of Sin30 degree".
    >>

    > double degtorad(double degrees)
    > {
    > return degrees/360 * 2 * 3.14;
    > }
    >
    > /* get sine 30 degrees */
    > sin( degtorad(30) );
    >>
    >> And how can I draw a Triangle or a rectangle shape.
    >>

    > The problem is there is no standard graphical system.
    >
    > Drawing lines is surprisingly tricky, and most sytems provide basic line
    > and polygon functions as standard. If you really want to know how to do
    > it, look up Brasenham's algorithm.
    > Once you have a line drawer, an open rectnagle or triangle is no problem.
    >
    > Drawing a filled triangle is also tricky. The normal approach is to cut it
    > in half so that yiu have a flat-topped and a flat-bottomed triange, and
    > then calculate start and end points for each scan line.
    >
     
    Malcolm, May 27, 2005
    #4
  5. Fahad

    Martijn Guest

    >> void capitalisewords(char *str)
    >> {
    >> char *ptr;
    >> if(isalpha(*str))
    >> *str = toupper(*str);
    >> ptr = str;
    >> while(ptr = strchr(ptr, ' '))
    >> {
    >> ptr++;
    >> if(isalpha(*ptr))
    >> *ptr = toupper(*ptr);
    >> }
    >> }


    Might as well snug it all in one loop (not using strchr that is) and use
    isblank or isspace instead - this way the function will be more generic (but
    agreed, not up to the users precise spec).

    --
    Martijn
    http://www.sereneconcepts.nl
     
    Martijn, May 28, 2005
    #5
    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. Fahad

    plz help to solve some problem

    Fahad, May 27, 2005, in forum: C Programming
    Replies:
    16
    Views:
    535
    Keith Thompson
    Jun 5, 2005
  2. Replies:
    1
    Views:
    387
  3. Replies:
    2
    Views:
    341
    Nick Keighley
    Nov 24, 2006
  4. Replies:
    1
    Views:
    349
  5. nocturnal
    Replies:
    1
    Views:
    533
    nocturnal
    Jul 10, 2009
Loading...

Share This Page