![]() |
| ||
| Comparisons I have to read in values from a file and output only the ones that past the test. However, I'm not sure how to compare a few of them. I need to skip the word if it ends with '\n', '\t', or a space. So, how exactly would you handle and test for this. I have the rest down path, just these three are giving me issues. He didn't tell us what the input file would look like, so I'm assuming it's one line has one word on it, so that's what I coded for. But then that leads to the problem that all the lines end with the \n char, hence my dilemma. Any suggestions of what to do? This code works so far, but it doesn't do anything if it ends in the last three bad[] chars. char bad[20] = {'{', '[', '(', '"', '‘', ',', '.', '?', ';', ':', '%', '@', '-', '}', ']', ')', '`', ' ', '\n', '\t'}; |
| ||
| Re: Comparisons Every line in a text file ends with '\n'. According to your instructions you would have to skip the last word of every line that is read. Lines do not have embedded '\n' characters. |
| ||
| Re: Comparisons Yeah, so I'm not entirely sure how to handle the coding for this. I mean, I'm basically done, I just don't know what to use as a test. If the input file looks like this one two three you're hiThen basically all the words should drop out cause they all either end with a space or a newline character, even though they aren't on the word technically. But, if you think of the space as a separator, then there's the issue that how would you determine if a character ends with a space. Then there is also the factor of how do you determine if it ends with a \t or \n character as well. The only way I can figure is that it's hard coded in, like word\nBut, if that's the case, it seems a little he would have told us that or something. I just don't know which one to code for. |
| All times are GMT -4. The time now is 12:17 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC