c - Warning initialization makes integer from pointer without a cast with fgets -


this question has answer here:

i want want read character string, on stdin, have chosen fgets. got warning: initialization makes integer pointer without cast.

here code:

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stddef.h>  #define max_linia 301  int main(int argc,char *argv[]){     char *buffer;     printf("enter input\n");     if (fgets(buffer,max_linia-1,stdin)==null) printf("error")     else printf("%s", buffer);     return 0: } 

you using buffer without initialising it, causes undefined behaviour.

you don't need use pointer, , can use char array instead (given max size defined):

char buffer[max_linia]; 

the fgets better written as:

if(fgets(buffer,sizeof(buffer),stdin)==null) 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -