Crea sito

Archivio per la categoria C programming

Check the endianness, C program

Here there is a really simple program written in C that you can use to check the endianness of the machine that you are using. #include <stdio.h> int main(){ unsigned int n = 1; char *p; p = (char*)&n; if (*p == 1)   printf(“Little Endian\n”); else if (*(p + sizeof(int) – 1) == 1) […]

Read a line from a file in C

Here there is a a function that can be used to read a line from a file in C #include <stdio.h> #include <stdlib.h> char* readline(FILE* f) { /* * calloc is like malloc, except it allocates cleared memory * so you don’t have random bytes in the memory space */ char* line = (char*) calloc(0, […]

Tags: , ,