Memory Allocation Using String (Please Help)
Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define size 10
void main()
{
int i,s;
char **names;
printf("Enter Size Of Array..\n");
scanf("%d",&s);
fflush(stdin);
names=(char **)malloc(s*sizeof(char));
for(i=0;i<s;i++)
{
names[i]=(char *)malloc(size*sizeof(char));
}
printf("\nEnter Data..\n");
for(i=0;i<s;i++)
{
scanf("%s",&names[i][0]);
}
printf("\nDisplaying Data..\n");
for(i=0;i<s;i++)
{
printf("%s",names[i][0]);
}
free(names);
getch();
}
I Don't Know What Seems To Be The Problem, What I'm trying to do is to read a set of names using memory allocation and print them and this doesn't work!
Help Would Be Really Appreciated.