When I compile function with \"gcc -o dene -Wall -ansi -pedantic-errors dene.c\" ,gcc emits no error.(can you look a line which starts with char ....,in if loop,)
In K&R and ANSI c, you must always put declarations at the start of a scope block. This requirement is relaxed in c99.
So, whats a scope block? A region delimited by {
and }
.
So in you above example the declaration
{
char *p=malloc(sizeof(char)*3); /* ...
is OK because it occurs immediately after a {
, while
{
char **cmainp=malloc(sizeof(char*)*1);
/*look*/ cmainp[0]=malloc(sizeof(char)*300); /*look*/
int len=0;...
fails because the assigment comes between the {
and the second declaration (int len=0;
).