Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to treat characters in a char array like integers?

 
thejwal pavithran
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Komal Arora
Ranch Hand
Posts: 91
Eclipse IDE Java Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

Go through this link. It may help you:

converting Strings to integers

 
Riiya Dsesuja
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use this :


 
thejwal pavithran
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Komal Arora wrote:Hey,

Go through this link. It may help you:

converting Strings to integers



thanks it helped
 
Anand Hariharan
Rancher
Posts: 272
C++ Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are better off using strtol rather than atoi.

http://www.iso-9899.info/wiki/Converting

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic