How do you use atoi to assign individual elements of a char array?

前端 未结 2 1133
Happy的楠姐
Happy的楠姐 2020-12-18 01:32

So as we all probably know, the atoi converts a char to a number. But, what do you do if you only want one of the array elements instead of the whole array?

2条回答
  •  一向
    一向 (楼主)
    2020-12-18 01:54

    Besides just using its integral value as shown by James, you could put it in a seperate buffer:

    char buf[2] = { temp[h], '\0' };
    num[h] = atoi(buf);
    

提交回复
热议问题