Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C File IO

Name: Anonymous 2007-03-02 19:21 ID:jQipi2LI

Guys, I fail hard at file I/O in C. What I'm trying to do is this:

Open the file
Read the first six bytes of the file
Compare it to blah, where blah is a character array
If it equals blah, do this stuff, otherwise
Shift forward one byte in the file and repeat.

The shifting part is kind of like a queue: basically, you go from FILE[0-5] to FILE[1-6] then FILE[2-7] and so on and so forth until EOF.

Can someone help me? In b4 forced indentation, Ruby on Rails, Opera, do your own homework, etc.

Name: Anonymous 2007-03-02 19:46 ID:vee8EO+m

char buf[6];

FILE* f = fopen("file", "rb");
if (fread(buf, 1, sizeof buf, f) == 6 && memcmp(buf, "nigger", sizeof buf) == 0)

memmove(buf, buf + 1, sizeof buf - 1)
buf[5] = fgetc(f); //feel free to give a shit about EOF

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List