Implicit declaration warning
For this code:
int i=0; char **mainp;
for(i=0;i<2;++i)
{
mainp[i]=malloc(sizeof(char)*200);
if(!scanf("%[^#],#",mainp[i]))
break;
if(i<2)
scanf("%[^#],#",mainp[i]);
}
GCC issues warnings:
warning: implicit declaration of function โscanfโ
warning: incompatible implicit declaration of built-in function โscanfโ
warning: โmainpโ may be used uninitialized in this function
And I am getting segmentation error at runtime
input: (p> Q) (Q> R) - R # -P output: (p> Q) (Q> R) - P (empt slot)
I had to give me (p> Q) (Q> R) - P -P // where should I fix in my code so that it expects me // exit
Problem # 1:
warning: 'mainp can be used uninitialized in this function
First, you need to allocate memory for an array of arrays.
char **mainp = malloc(sizeof(char*)*2);
Problem # 2:
warning: implicit declaration of function 'scanf
warning: incompatible implicit declaration of built-in function' scanf
You need to include stdio.h
at the beginning of the file:
#include <stdio.h>
Problem # 3: (Not included in your compilation warnings)
Don't forget to free both the allocated array elements and the array array.
a source to share
You shouldn't use functions without declaring them; you used scanf
but by no means was your code declared scanf
. Since it is a standard library function declared in one of the standard headers stdio.h
, so you just need to include it:
#include <stdio.h>
Brian's answer is good for the other part
a source to share