I've written this code in C. I need to solve a problem and there I'll have to input 5 line string including whitespace. This program will just give me output of all 5 line string including whitespace. By white space I mean on input I can put space before and char or after any char. That's why I've written this code but I can't understand why it's not working.
#include<stdio.h>
int main() {
char str[5][100];
for(int i=0;i<5;i++) {
scanf("%[^n\]",str[i]);
}
for(int j=0;j<5;j++) {
printf("%s\n",str[j]);
}
return 0;
}
I tried to use only
scanf("%s",str[i]);
but then it's ignoring all whitespace inside the input and trimming the output. Also I tried to use
scanf(" %[^\n]",str[i]);
this time little better but it's ignoring the all white space before any character a example input is like.
Robin Islam
// output showing
Robin Islam
// should show
Robin Islam
I just want to make this program to allow whitespace on every I mean output should show the same as input without ignoring space. Someone please help me. Tried lot's of way but don't know how to make it works or how......Help please
Thanks, Robin