| Author |
How to treat characters in a char array like integers?
|
thejwal pavithran
Ranch Hand
Joined: Feb 11, 2012
Posts: 113
|
|
hey guys i have a simple function which reads in two integer arrays and outputs the number of same elements in the 2 arrays.
eg:
input:
{11,22,12,13}
{44,55,22,11}
the output will be 2 here.
my function prototype is:
void compare(int list1[],int list2[]);
but theres a glitch.
the modules which call the function pass the lists as strings.
So now i should rewrite the function and the prototype would be:
void compare(char* input1,char* input2);
I have absolutely no idea on how to compare two integers this way. can Somebody please tell me how to compare two integers if they are in a string?.
initially input1 and input2 would give '{' on derefencing
|
on job hunt
|
 |
Komal Arora
Ranch Hand
Joined: Sep 30, 2010
Posts: 91
|
|
Hey,
Go through this link. It may help you:
converting Strings to integers
|
OCPJP
|
 |
Riiya Dsesuja
Greenhorn
Joined: Aug 31, 2012
Posts: 3
|
|
Use this :
|
Try our Restaurants or Order Pizza Online
|
 |
thejwal pavithran
Ranch Hand
Joined: Feb 11, 2012
Posts: 113
|
|
thanks it helped
|
 |
Anand Hariharan
Rancher
Joined: Aug 22, 2006
Posts: 252
|
|
You are better off using strtol rather than atoi.
http://www.iso-9899.info/wiki/Converting
|
"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
|
 |
 |
|
|
subject: How to treat characters in a char array like integers?
|
|
|