Simple print string array -
please let me know mistake simple code.
#include<stdio.h> #include<conio.h> void main() { int i,n; char a[100]; clrscr(); printf("\n enter size of array"); scanf("%d",&n); printf("\n enter array"); for(i=0;i<n;i++) scanf("%s",a[i]); printf("\n array \n"); for(i=0;i<n;i++) printf("%s",a[i]); getch(); }
my input enter size of array 2 enter array apple banana array (null) (null)
can explain why is? going wrong? if input single characters or s, same output.
thanks in advance
you not declaring array of string itself.
by char a[100];
means declaring array can hold 100 characters (one of them should null
proper string termination). in other words declaring 1 string.
whereas want array of strings, need char a[10][100];
. declare array of 10 strings, every string can hold 100 characters.
after updating code char a[10][100];
, getting following o/p (which looking for):
enter size of array3 enter arrayhi hello com array hi hello com
Comments
Post a Comment