The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.
I'm doing a coding project where I'm reading in data from a file into a linux kernel module (bad idea normally, I know, but we're ignoring that bit for the project).
Since this is kernel programming, stuff like fscan from stdio.h is off limits and I'm pretty sure I have to just iterate one character at a time into a buffer and then interpret the stuff in the buffer into variables. However, i can't remember what char equates to a carriage return and google is mainly turning up the various characters you get holding down alt when i search for ANSI characters.
I'm doing a coding project where I'm reading in data from a file into a linux kernel module (bad idea normally, I know, but we're ignoring that bit for the project).
Since this is kernel programming, stuff like fscan from stdio.h is off limits and I'm pretty sure I have to just iterate one character at a time into a buffer and then interpret the stuff in the buffer into variables. However, i can't remember what char equates to a carriage return and google is mainly turning up the various characters you get holding down alt when i search for ANSI characters.
Assuming the file is in UNIX format, you can check for a character equal to '\n'. Is there a maximum size of a line, or can they be of any length? If the latter, is the data from a streaming source or a buffer?
If it's from a buffer, just mark the start, iterate until you reach '\n', mark that, then memcpy (or whatever you have in the kernel) into an appropriately sized buffer.
If you're reading from a stream, allocate chunks of some fixed size and read into them byte-by-byte. When you reach '\n', join all the buffers together.
Assuming the file is in UNIX format, you can check for a character equal to '\n'. Is there a maximum size of a line, or can they be of any length? If the latter, is the data from a streaming source or a buffer?
If it's from a buffer, just mark the start, iterate until you reach '\n', mark that, then memcpy (or whatever you have in the kernel) into an appropriately sized buffer.
If you're reading from a stream, allocate chunks of some fixed size and read into them byte-by-byte. When you reach '\n', join all the buffers together.
There's no size limit to the lines, but the file itself is static and we don't have to worry about someone altering it on the fly for the assignment. Not sure which this falls under (though I think the former), I've been doing higher level stuff for years where I had APIs to work with.
Well, if there would (for example) never be a line longer than 1024 bytes, you could just read them into a buffer of that size, and then replace the first '\n' you found with a NULL.
Posts
DOS/Windows text files tend to end in \r\n.
Old Mac files apparently end in \r, although I am uncertain how it behaves now that the new Mac OSs are on a *nix base. I'd guess \n, but am not sure.
Here's a table of the ASCII set
Assuming the file is in UNIX format, you can check for a character equal to '\n'. Is there a maximum size of a line, or can they be of any length? If the latter, is the data from a streaming source or a buffer?
If it's from a buffer, just mark the start, iterate until you reach '\n', mark that, then memcpy (or whatever you have in the kernel) into an appropriately sized buffer.
If you're reading from a stream, allocate chunks of some fixed size and read into them byte-by-byte. When you reach '\n', join all the buffers together.
There's no size limit to the lines, but the file itself is static and we don't have to worry about someone altering it on the fly for the assignment. Not sure which this falls under (though I think the former), I've been doing higher level stuff for years where I had APIs to work with.
Steam Profile
3DS: 3454-0268-5595 Battle.net: SteelAngel#1772
This is correct. I believe that MacOS X uses \n as the newline.