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++);
}
}
「如果一個人不能確切地理解他/她在做什麼,那麼就不可能使用它們」 - 有點像整數?不,他們不是「硬」的。 – 2010-08-08 18:03:09
@Neil就像整數一樣,如果我們談論專業編程,但是你必須承認,整數和指針對於我們在這裏總是看到的大量程序員來說是不同的。在他們的案例中,只使用整數的程序有很高的工作機會。指針需要更多的猴子和更多的時間。在這個意義上他們更難。 – 2010-08-09 16:26:41