scan input string and store words in array in C -


i writing c program in want scan user given input this:

"hello how you" (one single line without quotes)

and each of word should in user defined array like
a[0]=hello
a[1]=how
a[2]=are
a[3]=you

here code link https://github.com/fzx-314/learning/blob/master/text.c function using scanning input is

    j=0;     for(i=0;i<4;i++)     {         scanf("%s",&a[j][i]);     } 

here function using print contents of array

for(i=0;i<2;i++)     for(j=0;j<4;j++)         printf("%s\t",a[i][j]); 

getting run time error

since want store two-dimensional char array. code should like

  char a[4][10];   for(i=0;i<4;++i){     gets(a[i]);   } 

it 4 strings , store them in different rows.

and can accessed in same way mentioned


Comments

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -

c# - Populating Gridview inside Listview ItemTemplate On Web User Control from Code Behind -