atoi函数转换报错 incompatible pointer type不兼容的指针类型

文章讨论了C语言中将字符数组地址间接传递给atoi函数时的报错问题,指出需进行类型转换以正确解析整数,修正后的代码示例包含在内。

代码段:

unit32_t buffer[4];//保存的地址值

uint32_t ID = atoi (&(buffer[0])); //报错

修改为:

unit32_t buffer[4];

uint32_t ID = atoi ((char *)&(buffer[0]));

 

PS C:\Users\34171\Desktop\code\WJ> make gcc -Wall -Wextra -std=c99 -O2 -o wj main.c recipe.c utils.c main.c: In function 'main': main.c:25:9: warning: implicit declaration of function 'readInt' [-Wimplicit-function-declaration] 25 | readInt(&choice, 0, 6); | ^~~~~~~ recipe.c: In function 'addRecipe': recipe.c:51:32: warning: passing argument 1 of 'getMultiSelection' from incompatible pointer type [-Wincompatible-pointer-types] 51 | getMultiSelection(newRecipe.flavors, &newRecipe.flavorCount, 7, flavorNames); | ~~~~~~~~~^~~~~~~~ | | | Flavor * In file included from recipe.c:1: recipe.h:99:29: note: expected 'int *' but argument is of type 'Flavor *' 99 | void getMultiSelection(int* items, int* count, int max, char** options); | ~~~~~^~~~~ recipe.c:58:32: warning: passing argument 1 of 'getMultiSelection' from incompatible pointer type [-Wincompatible-pointer-types] 58 | getMultiSelection(newRecipe.states, &newRecipe.stateCount, 6, stateNames); | ~~~~~~~~~^~~~~~~ | | | State * In file included from recipe.c:1: recipe.h:99:29: note: expected 'int *' but argument is of type 'State *' 99 | void getMultiSelection(int* items, int* count, int max, char** options); | ~~~~~^~~~~ recipe.c: In function 'modifyRecipe': recipe.c:190:41: warning: passing argument 1 of 'getMultiSelection' from incompatible pointer type [-Wincompatible-pointer-types] 190 | getMultiSelection(recipe->flavors, &recipe->flavorCount, 7, flavorNames); | ~~~~~~^~~~~~~~~ | | | Flavor * In file included from recipe.c:1: recipe.h:99:29: note: expected 'int *' but argument is of type 'Flavor *' 99 | void getMultiSelection(int* items, int* count, int max, char** options); | ~~~~~^~~~~ recipe.c:195:41: warning: passing argument 1 of 'getMultiSelection' from incompatible pointer type [-Wincompatible-pointer-types] 195 | getMultiSelection(recipe->states, &recipe->stateCount, 6, stateNames); | ~~~~~~^~~~~~~~ | | | State * In file included from recipe.c:1: recipe.h:99:29: note: expected 'int *' but argument is of type 'State *' 99 | void getMultiSelection(int* items, int* count, int max, char** options); | ~~~~~^~~~~ recipe.c: In function 'searchRecipes': recipe.c:275:37: warning: comparison of integer expressions of different signedness: 'MealType' and 'int' [-Wsign-compare] 275 | match = (r.mealType == mealChoice - 1); | ^~ PS C:\Users\34171\Desktop\code\WJ>
07-25
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值