的陣列,所以我想送一個輸入像字符串數組
ls -l | ./a.out
以下程序
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (int argc, char *argv[])
{
char virtualLs[100];
char eachLineOfLsInArray[100][100];
scanf("%[^\t]", virtualLs);
char *eachLineOfLs;
eachLineOfLs = strtok(virtualLs, "\n");
int loopCounterForStuffing;
loopCounterForStuffing = 0;
while (eachLineOfLs != NULL)
{
strcpy(eachLineOfLsInArray[loopCounterForStuffing], eachLineOfLs);
eachLineOfLs = strtok(NULL, "\n");
++loopCounterForStuffing;
}
char newLsArray[100][sizeof(eachLineOfLsInArray)/sizeof(char)];
int i;
for(i = 0; i < sizeof(eachLineOfLsInArray)/sizeof(char); i++)
{
char *array[10];
int k=0;
array[k] = strtok(eachLineOfLsInArray[i], " ");
while(array[k] != NULL)
{
array[++k] = strtok(NULL, " ");
}
newLsArray[i] = array;
printf ("res[%d] = %s\n", i, array[i]);
}
我在編譯收到以下錯誤消息
largest.c:31:17: error: array type 'char [10000]' is not assignable
newLsArray[i] = array;
~~~~~~~~~~~~~^
1 error generated.
的此程序的目的是將每行放入一個包含其單詞作爲數組的數組中。
我只是喜歡這個問題如何開始與「當我做X」,然後跟着它「但當然Y阻止我從來沒有試圖做X.」 – 2014-09-28 13:29:09
'char eachLineOfLsInArray [100] [100];'意味着sizeof(eachLineOfLsInArray)= 10000'。所以對於(i = 0;我<10000; i ++)'而你有'char newLsArray [100] [...]' – DOOM 2014-09-28 13:34:53