plz help to solve some problem

F

Fahad

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

Arafangion

Fahad said:
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.

First, C does not have strings.
Second, you want a formula or equation to help you derive Sin30 degrees.
Third, C does not have pen and paper.

I hope that helped.
(PS: Read your C book)
 
O

osmium

Fahad said:
Then "how can i get the value of Sin30 degree".

The sin() function in <math.h> will give you the answer in radians. Use
that function and then convert to degrees in your program. You will
probably get better results if you post one question per post. Otherwise,
people get the wrong impression about what you are up to.
 
W

Walter Roberson

The sin() function in <math.h> will give you the answer in radians. Use
that function and then convert to degrees in your program.

Urrr -- that's the description for asin(), not for sin().
 
K

Keith Thompson

Arafangion said:
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.
[...]

First, C does not have strings.

Of course it does, though C strings aren't first-class objects as they
are in some other languages.
 
K

Keith Thompson

osmium said:
The sin() function in <math.h> will give you the answer in radians. Use
that function and then convert to degrees in your program. You will
probably get better results if you post one question per post. Otherwise,
people get the wrong impression about what you are up to.

The sin() function takes an argument in radians. If you have an
argument in degress, you need to convert it to radians before calling
sin().
 
L

Lawrence Kirby

First, C does not have strings.

Sure it does. However C defines them as a data format rather than a
data type. C (roughly) defines a string as a sequence of characters
terminated by a null character
Second, you want a formula or equation to help you derive Sin30 degrees.

Or use the sin() function. The only reall issue is that it takes a value
in raqdians rather then degrees. Just remember that there are 2 PI radians
(think of the formula of a circle's circumference from its radius) in a
full circle i.e. 360 degrees.

Lawrence
 
P

pete

Keith said:
Arafangion said:
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.
[...]

First, C does not have strings.

Of course it does, though C strings aren't first-class objects as they
are in some other languages.

Strings aren't objects at all.
Every byte of a string is the begining of a string.
An object may contain several distinct strings.
A string may span two unrelated objects.
 
K

Keith Thompson

pete said:
Keith said:
Arafangion said:
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. [...]

First, C does not have strings.

Of course it does, though C strings aren't first-class objects as they
are in some other languages.

Strings aren't objects at all.

Sure they are. A string is "a contiguous sequence of characters
terminated by and including the first null character". An object is a
"region of data storage in the execution environment, the contents of
which can represent values".
Every byte of a string is the begining of a string.
Yes.

An object may contain several distinct strings.
Yes.

A string may span two unrelated objects.

Only if the objects are subobjects of an enclosing object; otherwise
any attempt to treat parts of two unrelated objects as a string must
invoke undefined behavior.

Objects can overlap.
 
P

pete

Keith Thompson wrote:
Only if the objects are subobjects of an enclosing object; otherwise
any attempt to treat parts of two unrelated objects as a string must
invoke undefined behavior.

You're making that up.
If two unrelated objects can be determined to be contiguous
and if only the higher addressed object has a null byte,
then there are no words in the standard
which exempt a standard library string output function, like puts,
from working with an argument that points to the lower addressed object.

If puts can't incremenent a pointer through the string without
invoking undefined behavior, then it's up to puts to find another way.

/* BEGIN new.c */

#include <stdio.h>

#define HELLO "Hello "

int main(void)
{
char hello[sizeof HELLO - 1] = HELLO;
char world[] = "world";

if (world == hello + sizeof hello) {
puts(hello);
/* puts("wow"); */
} else {
puts("Hello world");
}
return 0;
}

/* END new.c */
 
P

pete

pete said:
You're making that up.

I think I'm going to change my tune on this one.
The string functions in the library are said to be intended
to work with arrays and objects.

Then I'll say instead that there are no string types.
 
L

Lawrence Kirby

You're making that up.
If two unrelated objects can be determined to be contiguous

Then you have established a relation between them so they aren't
unrelated.

and if only the higher addressed object has a null byte,
then there are no words in the standard
which exempt a standard library string output function, like puts,
from working with an argument that points to the lower addressed object.

The rules of pointer arithmetic in normal code do not allow access of
array elements beyond the array size. As such a string as C defines it
MUST have a null character within the original array object. If you
violate this requirement when calling a standard library function that
stipulatesa pointer to a string then you invoke undefined behaviour.
If puts can't incremenent a pointer through the string without invoking
undefined behavior, then it's up to puts to find another way.

No, you have violated puts()'s call requirements by not passing it a valid
string.
/* BEGIN new.c */

#include <stdio.h>

#define HELLO "Hello "

int main(void)
{
char hello[sizeof HELLO - 1] = HELLO; char world[] = "world";

if (world == hello + sizeof hello) {

Consider that even though the 2 pointer values ``world'' and
``hello + sizeof hello'' may compare equal they need not be the same
pointers. For example they may contain segment/boundary information which
is not used in the comparison. It simply may not be possible to access any
data in world from a pointer to hello (e.g. the system would trap from
such an access). This might make it clearer why a pointer to a character
in hello is not a valid pointer to a string, even at this point in the
code.
puts(hello);
/* puts("wow"); */
} else {
puts("Hello world");
}
return 0;
}
}
/* END new.c */

Lawrence
 
K

Keith Thompson

pete said:
You're making that up.

I resent that.
If two unrelated objects can be determined to be contiguous
and if only the higher addressed object has a null byte,
then there are no words in the standard
which exempt a standard library string output function, like puts,
from working with an argument that points to the lower addressed object.

I believe you're right. I forgot that the standard allows for the
possibility of two objects being detectably adjacent (it has to in
order for pointer comparison to work properly). But in that case I'd
say that the two (or more) object can be treated as a single object,
given the standard's definition of the term. (And, of course, as
Lawrence Kirby points out, the objects are then no longer unrelated.)
 
P

pete

Keith said:
pete said:
Keith said:
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.
[...]

First, C does not have strings.

Of course it does,
though C strings aren't first-class objects as they
are in some other languages.

Strings aren't objects at all.

Sure they are.

Then what's a first-class object?
 
K

Keith Thompson

pete said:
Keith said:
pete said:
Keith Thompson wrote:

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.
[...]

First, C does not have strings.

Of course it does,
though C strings aren't first-class objects as they
are in some other languages.

Strings aren't objects at all.

Sure they are.

Then what's a first-class object?

It's a rather vaguely defined concept, depending on the operations
supported on a given type.

C scalar objects, for example, are considered first-class because they
support assignment, comparison, passing as parameters, etc. Arrays
aren't, because they don't. Structures support assignment but not
comparison; whether they're "first-class" is probably a judgement
call.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top