- C program to take a paragraph as input from user using scanf function.
- How to take a multi line input form user using getchar function.
"%[^;]s" specifies that scanf will take all characters as input except ';' character. As soon as user enters ';' character scanf function stops reading input and returns.
C program to take multiline string input from user using scanf function.
#include<stdio.h> int main() { char inputString[128]; printf("Enter a multi line string( press ';' to end input)\n"); scanf("%[^;]s", inputString); printf("Input String = %s", inputString); return 0; }Output
Enter a multi line string( press ';' to end input) The quick brown for Jumps over the lazy dog; Input String = The quick brown for Jumps over the lazy dog
C program to take a paragraph as input from user using getchar function.
#include<stdio.h> int main() { char inputString[128], c; int index = 0; printf("Enter a multi line string( press ';' to end input)\n"); while((c = getchar()) != ';'){ inputString[index++] = c; } inputString[index] = '\0'; printf("Input String = %s", inputString); return 0; }Output
Enter a multi line string( press ';' to end input) The quick brown for Jumps over the lazy dog; Input String = The quick brown for Jumps over the lazy dog