|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||||
|
|||||
|
ANSI C: Checking for a blank line in an input file
Hello, I am trying to determine if the next line is blank in my input file, and seem to be having difficulty :/
Here is my function: C Code:
I figure if it is blank, it will eat up the \n in the getc, and then be at the correct location for the next line, but if it has data on that line then it will move the pointer back one character to the correct location for when it gets read in. Unfortunately, it does not seem to be moving the pointer back at all, it always eats up that character, and so every non-blank line gets read in without the first character. |
|
#2
|
||||
|
||||
|
Line ends in text files vary. The convention on Windows is to use CR-LF. That is "\r\n". You may need to take that into account. While in text mode getc() will convert CR-LF to '\n', but fseek() still regards it as two characters.
Clifford |
|
#3
|
|||||
|
|||||
|
Quote:
Thank you, Clofford. I tested the newline in file with this function: Here is a segment of ouput: Code:
119 97 114 112 45 100 114 105 118 101 32 109 111 116 111 114 10 49 49 52 52 45 48 49 10 66 48 49 55 10 10 10 102 108 97 110 103 101 32 104 105 110 103 101 10 So I think it exclusively uses \n at the ends. This output should look like: Quote:
But instead is read in as: Quote:
So I could be confused, but I don't think the line ends are causing the problem, I think the problem is that my fseek function is wrong. edit: Yes, that is the problem, I just tested it by adding the code To the function that is reading in the data, I figure if it works, it will print the next character in the file, back up one character, and then print that one again, then back up again, so the output for the segment above should be c=x c=x Where x is the next character being read in, but instead it is giving me c=x c=y where x and y are not the same character. So my fseek function must be incorrect. |
|
#4
|
||||
|
||||
|
I think that your problem is not thinking things through, despite hints. Have you visited the Commonly Asked Questions thread?
Would you care to post the EXACT contents of your target file and the EXACT code of your processor file? It's a huge pain in the *** for your respondents, but it's your best hope.
__________________
C/C++ pointers (Original in the "Commonly Asked Questions" thread). |
|
#5
|
||||||||||
|
||||||||||
|
Quote:
Of course, and thank you. Program definitions (defines boolean and my data structure: PARTS_RECORD) C Code:
Header file: C Code:
(note that the name and keytype lines will always have data, but there may be between 0 and 3 supplier codes, if there are 3 codes, each code has its own line, if there are fewer, the ones that do not exist are represented with a blank line) My C file: C Code:
|