Created
August 5, 2016 22:10
-
-
Save nicolashohm/f6e50ddccb40ff95c05a9ccf64490472 to your computer and use it in GitHub Desktop.
find first set in file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int main(int argc, char *argv[]) { | |
printf("Start reading...\n"); | |
FILE *fp = fopen(argv[1], "r"); | |
int res = 0, buff = 0, ffs = 0, pos = 0; | |
while (fread(&buff, sizeof(int), 1, fp) == 1) { | |
ffs = __builtin_ffs(buff); | |
if (ffs > 0) { | |
printf("ffs at %d\n", pos+ffs); | |
break; | |
} | |
pos += sizeof(int); | |
} | |
printf("Scanned %d bytes\n", pos); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment