In my code,i need to use nested while loop and it is not working correctly.It is skiping the 1st iteration of the nested loop[This is my guess].For example,
#include<iostream>
#include<string>
using namespace std;
void solve()
{
char s[20];
char c;
int i=0;
while(true)
{
scanf("%c",&c);
if(c=='\n')
{
break;
}
if(c!=' ')
{
s[i]=c;
i++;
}
}
cout<<s<<endl;
}
int main()
{
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
In this above code,when i give the below input,i dont get accurate result.
It should have take 3 string input.But it terminates the program after taking 2 string input. What i want from the code is, if the user input of t=3,then i need to take 3 string input in char datatype array using loop. But my code is not giving the desired result. What is the problem of this code?