P185. Program to allocate dynamic memory for ‘n’ strings, scan it and print it.

 #include<stdio.h>

#include<stdlib.h>

void main()

{

int n,i;

printf("Enter number of string : ");

scanf("%d",&n);

 

char **p;

p=malloc(sizeof(char *)*n);

 

for(i=0;i<n;i++)

{

   p[i]=malloc(sizeof(char)*10);

   scanf("%s",p[i]);

}

 

for(i=0;i<n;i++)

   printf("%s\n",p[i]);

 

}

Comments