我想從用戶的輸入,我沒有確切的輸入長度,所以我使用malloc,我分裂他們之間的空間字符並且只需要打印一個數組,但我得到警告,即賦值時將指針整數,未在下面一行鑄造:在C:鑄造警告在C:賦值整數從指針沒有鑄造
array[i++] = p;
和我的整個程序如下:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char buf[] ="abc qwe ccd";
int i;
char *p;
char *array=malloc(sizeof(char));
i = 0;
p = strtok (buf," ");
while (p != NULL)
{
array[i++] = p;
p = strtok (NULL, " ");
}
for (i=0;i<3; ++i)
printf("%s\n", array[i]);
return 0;
}
能
人請告訴我我的代碼有什麼問題。 謝謝。
Thanx alot。指針總是殺了我:( –
@BASEERHAIDER,不客氣,需要一點時間才能適應。 –