Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

how to use getline in c programming

#include <stdio.h>

int main()

{

int bytes_read;

int size = 10;

char *string;

printf ("Please enter a string: ");

/* These 2 lines are very important. */

string = (char *) malloc (size);

bytes_read = getline (&string, &size, stdin);

if (bytes_read == -1)

{

puts ("ERROR!");

}

else

{

puts ("You entered the following string: ");

puts (string);

printf ("
Current size for string block: %d", bytes_read);

}



return 0;

}
Source by www.studymite.com #
 
PREVIOUS NEXT
Tagged: #getline #programming
ADD COMMENT
Topic
Name
3+8 =