Hello. I got a problem of that type:
for example i have a simple program like this:

int main(){

now if i define time to be 10 sec, prog works fine.

#define TIME 10

but i am trying to do something like that:

char time; // or int time;
time = "10";

and it's not working. Prog sleeps untill i finish it myself manualy.
The same thing i am trying to do in simple socket app to connect the net.
This line:

dest_addr.sin_port = htons(DEST_PORT);

when DEST_PORT is defined, it's ok. But i'm trying to rebuild this like with that app with sleep. The errors i've got are:
passing argument 1 of 'htons' makes integer from pointer without a cast
assignment makes integer from pointer without a cast.
Please help me how to do it...

8 Years
Discussion Span
Last Post by somename

Numbers and strings are two different kinds of thing.

You'll need to convert between them. Use strtol() or strtoul() to turn your string into a number (long or unsigned long respectively).

Hope this helps.

char time; // or int time;
time = "10";

This is the prototype of sleep: unsigned sleep(unsigned seconds); Meaning it accepts an unsigned type argument and returns an unsigned type int time = 10; will work correctly as long as time is an unsigned integer. time = "10"; is not an integer. It is a string, an incorrect declared string, but a string nevertheless. #define TIME 10 TIME is a constant of an unsigned integer. Therefore it woks.


Duoas, thank you! Problem solved. Yes, i was about how to convert number to string, just didnt know how to express myself properly. Thanks!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.