I'm trying to create an array of strings using calloc method and I'm getting quite a lot many errors.
int main() {
int T,i;
char *w;
char **s;
w=(char*)calloc(100,sizeof(char));
scanf("%d",&T);
s=(char**)calloc(T,sizeof(char));
s=(char*)calloc(100,sizeof(char));
for(i=0;i<T;i++)
{
scanf("%s",w);
s[i]=w;
}
}
In the above code T is the number of strings and w is the maximum size of the string. Please shed some light on as to how I should be declaring string arrays dynamically and statically.
calloc(T,sizeof(char))==>calloc(T,sizeof(char*)). But anyway, you immediately overwrite that pointer.char[NSTRINGS][STRINGLEN]. 2) Allocate an array of strings dynamically:calloc(NSTRINGS,sizeof(char*)). 3) Allocate one string dynamically:calloc(STRINGLEN,sizeof(char))