hello:
did anyone know how to use atoi.........atoi is use to convert char to int right?????then how to use it.....i mean did anyone can show the example for me,please???thanks
hello:
did anyone know how to use atoi.........atoi is use to convert char to int right?????then how to use it.....i mean did anyone can show the example for me,please???thanks
#include <cstdlib>
#include <iostream>
using namespace std;
main()
{
int val;
long val2;
char *string = "1234567";
val = atoi(string); // converts to int
val2 = atol(string); // converts to long
return 0;
}
prototypes of atoi and atol.
int atoi(const char *);
long atol(const char *);
The experimenter who does not know what he is looking for will not understand what he finds.
- Claude Bernard
hello
u are using pointer right?????besides using pointer,do u know the easier way to use the atoi.....coz i wan to make my program shorter
atoi converts character strings only (whether you create strings with arrays or pointers, does not matter). It is seen from the prototype.
Are you trying to convert a single character to integer (a digit) ? If this is the case you may try something like this.
int a;
char b = '6';
a = b - '0';
The experimenter who does not know what he is looking for will not understand what he finds.
- Claude Bernard
morning:
hello,ozgulker......in my case.....i want to using atoi to make year......so got any idea???i dont want to use pointer coz i really cant understand how the pointer work....
do u know how to make the date in DD/MM/YYYY format.....need to use % to search this'/' or what.......???
then,i got last question here.......when i using characters array to write the file ,then when i read it,i cant read all...so how to solve it????
now i doing a project about personnel detail..so i need to write quite a long sentences in the file,then the output of the file cannot display line by line coz some is long and some is short.....so do u know how to make it look nice and neet!!!!
hope can hear from u soon.....