I have an issue with pipes in Linux. Looks like space characters are lost after piping. Running the following C++
code
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main(){
char s[] = "ab cd", c;
int n = strlen(s);
for(int i = 0; i<n && (cin >> c); i++)
if(s[i] != c){
printf("wrong at %d : '%c' != '%c' \n", i, s[i], c);
break;
}
return 0;
}
from
echo "ab cd" | ./checker
shell command gives
wrong at 2 : ' ' != 'c'
Is it normal behavior? How to avoid losing characters in pipes?