read line c code example
Example 1: console readline c
Here, take input from the user. Since age is an integer, we typecasted it using Convert.ToInt32() Method. It reads the next line from the input stream. It blocks until Enter key is pressed. Hence it is commonly used to pause the console so that the user can check the output.
using System;
using System.IO;
class GFG {
public static void Main()
{
int age;
string name;
Console.WriteLine("Enter your name: ");
name = Console.ReadLine();
Console.WriteLine("Enter your age: ");
age = Convert.ToInt32(Console.ReadLine());
if (age >= 18)
{
Console.WriteLine("Hello " + name + "!"
+ " You can vote");
}
else {
Console.WriteLine("Hello " + name + "!"
+ " Sorry you can't vote");
}
}
}
Example 2: c read a whole string from a file
#define _GNU_SOURCE
getline(&line, &len, fp);