Arjun Posted January 9, 2019 Share Posted January 9, 2019 hello guys, actually i want to assign char array value to int variable ,,, just like i want .. char myarray[4] = {'0','x','2','3'}; int i = atoi(myarray); printf("%d\n", i); it is printing 0,,, ----------------------------------------- but if i use value char myarray[4] = {'0','2','2','3'}; int i = atoi(myarray); printf("%d\n", i); then it is working .... can you guys please help me out from this problem ..... Thank-you Regards Arjun Link to comment Share on other sites More sharing options...
xc6lx45 Posted January 9, 2019 Share Posted January 9, 2019 Hi, I think you'll need to add a terminating zero to the string (C string convention), otherwise junk may appear directly afterwards. Link to comment Share on other sites More sharing options...
Question
Arjun
hello guys,
actually i want to assign char array value to int variable ,,,
just like i want ..
char myarray[4] = {'0','x','2','3'};
int i = atoi(myarray);
printf("%d\n", i);
it is printing 0,,,
-----------------------------------------
but if i use value
char myarray[4] = {'0','2','2','3'};
int i = atoi(myarray);
printf("%d\n", i);
then it is working ....
can you guys please help me out from this problem .....
Thank-you
Regards
Arjun
Link to comment
Share on other sites
1 answer to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.