/*WAP to use array of pointers */
/* and Use of malloc */
#include<stdio.h> #include<conio.h> #include "alloc.h" main( ) { char *names[6] ; char n[50] ; int len, i ; char *p ; for ( i = 0 ; i <= 5 ; i++ ) { printf ( "\nEnter name " ) ; scanf ( "%s", n ) ; len = strlen ( n ) ; p = malloc ( len + 1 ) ; strcpy ( p, n ) ; names[i] = p ; } for ( i = 0 ; i <= 5 ; i++ ) printf ( "\n%s", names[i] ) ; }
No comments:
Post a Comment