【发布时间】:2010-08-08 16:54:54
【问题描述】:
gcc 4.4.4 c89
warning assignment makes integer from pointer without a cast
**devices = device_buff;
warning: value computed is not used
*devices++;
我通过以下代码收到上述警告。我想要做的是从用户那里获得输入。并将该 char 数组分配给指针数组。所以我的指针数组将包含所有输入的设备。但是,我在这条线上得到了一个 UB:
**devices = device_buff;
非常感谢您的建议,
static void device_input()
{
#define DEVICE_SIZE 80
char device_buff[DEVICE_SIZE] = {0};
char **devices = NULL;
size_t i = 0;
for(i = 0; i < 3; i++) {
printf("Enter device name: ");
fgets(device_buff, (size_t)DEVICE_SIZE, stdin);
**devices = device_buff;
*devices++;
}
/* NULL terminate last element */
*devices = NULL;
printf("Display devices\n");
while(*devices != NULL) {
printf("Device [ %s ]\n", *devices++);
}
}
【问题讨论】: