1. Engineering
  2. Computer Science
  3. g2c should read a line of text from the terminal...

Question: g2c should read a line of text from the terminal...

Question details

g2.c should read a line of text from the terminal but causes a segmentation violation. Correct the program.

g2.c:

#include <stdio.h>
#include <stdlib.h>

int main ()
{
char * buf;
int num;
num = 1 << 31;
buf = malloc(num) ;
fgets (buf, 1024, stdin) ;
printf ("%s\n", buf) ;
return(1);
}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution