![]() |
|
|
#2 (permalink) |
|
WARNING: FLAMMABLE
Location: Ask Acetylene
|
There is a function called printf or sprintf that can help you convert strings to in. Google "String to int" or "Convert string to int".
Google is a programmers second best friend, second only to java...
__________________
"It better be funny"
|
|
|
|
|
#3 (permalink) |
|
I am Winter Born
Location: Alexandria, VA
|
The function atoi() turns a char* into an integer, with certain constraints.
There can be whitespace in front of the integer, but no alphabet characters. The number stops when a non-integer character is read. Valid strings to pass to atoi(): " 103a39" -> 103 "9438745" -> 9438745 "-394" -> -394 Invalid strings: "a5445a" ".25465" |
|
|
|
|
#6 (permalink) |
|
Crazy
|
Use strtol().
(Error and sanity checks omitted) Code:
char *ptr = "10:45pm";
char *endptr;
int hours, min;
hours = strtol(ptr, &endptr, 0);
/* endptr now set to ":45pm" */
if (endptr == NULL || *endptr != ':')
report_error("time format");
endptr++;
ptr = endptr;
min = strtol(ptr, &endptr, 0);
/* endptr now set to "pm" */
__________________
I want no escape. Last edited by roboshark; 09-13-2004 at 05:07 AM.. |
|
|
| Tags |
| int, string |
| Thread Tools | |
|
|