Write And Read String Binary File C

[Solved] Write And Read String Binary File C | Elixir - Code Explorer | yomemimo.com
Question : c read binary file

Answered by : michael-mainbird

void ReadFile(char *name)
{	FILE *file;	char *buffer;	unsigned long fileLen;	//Open file	file = fopen(name, "rb");	if (!file)	{	fprintf(stderr, "Unable to open file %s", name);	return;	}	//Get file length	fseek(file, 0, SEEK_END);	fileLen=ftell(file);	fseek(file, 0, SEEK_SET);	//Allocate memory	buffer=(char *)malloc(fileLen+1);	if (!buffer)	{	fprintf(stderr, "Memory error!"); fclose(file);	return;	}	//Read file contents into buffer	fread(buffer, fileLen, 1, file);	fclose(file);	//Do what ever with buffer	free(buffer);
}

Source : https://www.linuxquestions.org/questions/programming-9/c-howto-read-binary-file-into-buffer-172985/ | Last Update : Fri, 25 Feb 22

Question : Read Binary File in C Language

Answered by : muhammad-abdullah-jxze1et1y350

int main()
{ FILE *file = fopen("input.txt", "r"); char buffer[2048]; if (file) { /* Loop will continue until an end of file is reached i.e. fread returns 0 elements read */ while (fread(buffer, 4, 1, file) == 1) { printf("%s", buffer); } fclose(file); }
}

Source : https://stackoverflow.com/questions/64039355/c-program-to-open-binary-elf-files-read-from-them-and-print-them-out-like-obj | Last Update : Mon, 03 Oct 22

Answers related to write and read string binary file c

Code Explorer Popular Question For Elixir