C Program to accept a paragraph(till @) using scanf function.
Objective
Write a C program to accept a multi-line paragraph until a specific symbol (@) is entered.
Algorithm / Approach
- Declare a large character array
str[150]. - Use
scanf("%[^@]", str)to read the input. - Print the paragraph.
main.c
#include<stdio.h>
int main() {
char str[150];
printf("Enter a Paragaraph to exit enter @:");
scanf("%[^@]", str);
printf("Paragraph is: %s",str);
return 0;
}
Expected Output
Enter a Paragaraph to exit enter @: C is a general-purpose, procedural, language@ Paragraph is: C is a general-purpose, procedural, language
Explanation of the Program
- Similar to reading a sentence, we use the scanset specifier
%[^@]. - This tells
scanfto keep reading everything—including spaces, tabs, and even Enter key presses (newlines)—until it sees the exact@symbol. This is highly useful for reading bulk multi-line text input in console applications.
Complexity
Time Complexity
O(n)
Space Complexity
O(n)