+ 2

Input string with new line

What is th code or statement for input multiline sentence

28th Jun 2019, 7:10 AM
MD Sisir
MD Sisir - avatar
1 Réponse
+ 2
I tried this, it's just a modified version from sample for reading string with whitespaces, I replaced \n in the sample with a . (period) character. This code will keep reading the input until specified length (50 characters), or if the input character was a '.' (period). #include <stdio.h> #include <string.h> int main() { char buffer[51]; // read up to a max of 50 char // or when a '.' character found scanf("%50[^.]s", buffer); printf("%u characters read:\n%s\n", strlen(buffer), buffer); return 0; }
29th Jun 2019, 1:46 AM
Ipang