reset password
Author Message
dliang
Posts: 35
Posted 21:23 Jan 30, 2020 |

Professor Kennan

What should we do, when we having a line-feed(InputStream), should we skip it or jump into the next line. 

240812281
Posts: 7
Posted 21:25 Jan 30, 2020 |

you can use skip() to skip the line-feed since line-feed is 1 byte, so just use skip(1). same for space

dliang
Posts: 35
Posted 21:35 Jan 30, 2020 |
240812281 wrote:

you can use skip() to skip the line-feed since line-feed is 1 byte, so just use skip(1). same for space

Thank you, another problems will be how can we deal in a situation, when the image had different height and widths. (I tried to used if-else, but it said 10(linefeed)  is not a valid constant. Therefore,  I can't used char or int compare and equal it. 

 

dliang
Posts: 35
Posted 21:37 Jan 30, 2020 |

Maybe I can use Scanner

240812281
Posts: 7
Posted 21:43 Jan 30, 2020 |
dliang wrote:
240812281 wrote:

you can use skip() to skip the line-feed since line-feed is 1 byte, so just use skip(1). same for space

Thank you, another problems will be how can we deal in a situation, when the image had different height and widths. (I tried to used if-else, but it said 10(linefeed)  is not a valid constant. Therefore,  I can't used char or int compare and equal it. 

There are different ways to do that, think about it, since each character is 1 byte, and also the height and width are separated by space. Take a time to think what you can do to let the program read those number. You might need to do one for height and one for width since they are not always the same. (PS. I did not get to that far, but I am trying to run it on my head). If my explaination does not make sense to you, wait for Keenan to give you a better explaination and hint.

240812281
Posts: 7
Posted 21:44 Jan 30, 2020 |
dliang wrote:

Maybe I can use Scanner

Scanner only works for text IO if I remember correctly, anything related to binary IO we need to use the things we learned this week.

ccasti26
Posts: 4
Posted 21:56 Jan 30, 2020 |

I used a method similar to the TestFileStream example in the book where '-1' is used to know when the end of the file was reached. Modify it so you looking for the white space character, not '-1'. When it reaches the white space, nothing will happen, so your next 'read' will be the character AFTER the white space!

Edit: I listed the wrong example from the book. It should be more helpful now!

Last edited by ccasti26 at 22:26 Jan 30, 2020.
dliang
Posts: 35
Posted 21:57 Jan 30, 2020 |
240812281 wrote:
dliang wrote:
240812281 wrote:

you can use skip() to skip the line-feed since line-feed is 1 byte, so just use skip(1). same for space

Thank you, another problems will be how can we deal in a situation, when the image had different height and widths. (I tried to used if-else, but it said 10(linefeed)  is not a valid constant. Therefore,  I can't used char or int compare and equal it. 

There are different ways to do that, think about it, since each character is 1 byte, and also the height and width are separated by space. Take a time to think what you can do to let the program read those number. You might need to do one for height and one for width since they are not always the same. (PS. I did not get to that far, but I am trying to run it on my head). If my explaination does not make sense to you, wait for Keenan to give you a better explaination and hint.

 

dliang
Posts: 35
Posted 21:59 Jan 30, 2020 |
240812281 wrote:
dliang wrote:

Maybe I can use Scanner

Scanner only works for text IO if I remember correctly, anything related to binary IO we need to use the things we learned this week.

Actually, it works.................I just figure it out, with some change

 

kknaur
Posts: 540
Posted 13:35 Jan 31, 2020 |

All good suggestions.  You can either skip(1) the new line character or if you are reading the entire line byte by byte (character by character), then you can stop at the end of the line when the current byte that is read is the value of the new line character (after casting to char of course).