1

I have a program that reads data from stdin. This data is a sequence of bytes. If there is a byte describing a new line in it (in hex: 0x0A), scanf stops reading.

Can I mask this byte, so that scanf continues to read the whole sequence?

It is important that the memory, that is written by scanf contains the newline-byte.

laurent
  • 88,262
  • 77
  • 290
  • 428
Stanley F.
  • 1,846
  • 16
  • 29

2 Answers2

3

Without seeing your code, I can't make a precise recommendation. But if your goal is take the input "as-is", I'll recommend read() as an alternative to scanf(). See this question for someone who had the exact opposite issue.

Community
  • 1
  • 1
chrisaycock
  • 36,470
  • 14
  • 88
  • 125
0
scanf("%[^`]s", str);

You can use some thing like this. `\n will now be the terminating sequence of characters.
You can replace ` using any other character or even a group of them and input will end with that character followed by a \n.

toofast1227
  • 160
  • 1
  • 15
  • Thats nearly what I'm looking for: to change the terminating sequence. The problem is: I only have the compiled binary and can only change the input... – Stanley F. Jan 19 '11 at 08:41
  • in that case you can preprocess the input using regular expression s/\n//g which basically is substitute \n with \0... the expression used might depend on language (e.g. perl)/tool (e.g. sed) you use but this is usually the way it is – toofast1227 Sep 14 '11 at 22:40
  • PS - i know it comes too late :P – toofast1227 Sep 14 '11 at 22:43