So I want to send an input like
ls -l | ./a.out
to the following program
#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]);
}
I get the following error message in compilation
largest.c:31:17: error: array type 'char [10000]' is not assignable
newLsArray[i] = array;
~~~~~~~~~~~~~ ^
1 error generated.
The purpose of this program is to put each line in to an array that contains its word as an array.
char eachLineOfLsInArray[100][100];meanssizeof(eachLineOfLsInArray) = 10000. sofor(i = 0; i < 10000; i++)whereas you gotchar newLsArray[100][...]