# plz help to solve some problem

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

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.

2. ### -berlin.deGuest

> 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

> 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-

Regards, Jens
--
\ Jens Thoms Toerring ___ -berlin.de
\__________________________ http://www.toerring.de

-berlin.de, May 27, 2005

3. ### MalcolmGuest

>.
> 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".
>

{
return degrees/360 * 2 * 3.14;
}

/* get sine 30 degrees */
>
> 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. ### MalcolmGuest

"Malcolm" <> wrote in message
news:d785uj\$ig3\$-infra.bt.com...
>
>>.
>> 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".
>>

> {
> return degrees/360 * 2 * 3.14;
> }
>
> /* get sine 30 degrees */
>>
>> 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
5. ### MartijnGuest

>> 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