Heya there,
i recently started to learn the C++ language and i am trying out things.
The deal here is i want to replace 4 spaces with a tab.The code seems fine to me,but its not proper as when i run it the 4 spaces are replaced by 6 spaces,5-7 and so on.I am at a dead end and any help would be appreciated.Here is my code:
Thanks for your time.Code:#include <iostream> using namespace std; char x; int spaces=0; int main() { char x; int spaces=0; while(cin.get(x)) { if (x !=' ') { if (spaces>0) { for (int i=0; i<spaces; i++) { cout<<' '; } spaces=0; } cout<<x; } else { if (++spaces==4) { cout<<'\t'; spaces=0; } } } }