Skip to content

Instantly share code, notes, and snippets.

@pol51
Last active August 29, 2015 14:04
Show Gist options
  • Save pol51/3bb2044591b99c4fe225 to your computer and use it in GitHub Desktop.
Save pol51/3bb2044591b99c4fe225 to your computer and use it in GitHub Desktop.
read inverted word from a text file
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv)
{
FILE *file = fopen("data.txt", "r");
if (!file)
return EXIT_FAILURE;
char buffer[256];
while (fgets(buffer, sizeof(buffer), file))
{
int i, value = 0;
for (i = 8; --i >= 0;)
value = (value<<1) | buffer[i] == '1';
printf("%d\n", value);
}
fclose(file);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment