Ubuntu Pastebin

Paste from Bram at Thu, 5 May 2016 17:35:51 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>

//OPEN CONFIG FILE IN OUR APPLICAITONS DIRECTORY OR CREATE IT IF IT DOESN'T EXIST
FILE *file1;
unsigned char file_data[100];
const char *filename1 = "Rebox/test.rbx";

file1 = fopen(filename1, "rb");
if (file1)
{
	//----- FILE EXISTS -----
	fread(&file_data[0], sizeof(unsigned char), 100, file1);

	printf("File opened, some byte values: %i %i %i %i\n", file_data[0], file_data[1], file_data[2], file_data[3]);

	fclose(file1);
	file1 = NULL;
}
else
{
	//----- FILE NOT FOUND -----
	printf("File not found\n");

	//Write new file
	file1 = fopen(filename1, "wb");
	if (file1)
	{
		printf("Writing new file\n");
		file_data[0] = 10;
		file_data[1] = 11;
		file_data[2] = 12;
		file_data[3] = 13;

		fwrite(&file_data[0], sizeof(unsigned char), 100, file1) ;

		fclose(file1);
		file1 = NULL;
	}
}
Download as text