Skip to content

OverLore/C-File-reader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C-File-reader

A file for read inside file and find specific value at a given attribute (category.attribute) Support: string, int, float, double, array of int, array of float, array of double

Examples of code:

Get a string in file:

char* returnedString = GetStringInFile(file, "Credits.message");
printf("%s\n", returnedString);
free(returnedString);

Get an int in file:

int returnedInt = GetIntInFile(file, "Credits.int");
printf("%d\n", returnedInt);

Get a float in file:

float returnedFloat = GetFloatInFile(file, "Credits.float");
printf("%f\n", returnedFloat);

Get a double in file:

float returnedDouble = GetDoubleInFile(file, "Credits.double");
printf("%lf\n", returnedDouble);

Get an int array in file:

int returnedIntsLen = 0;
int* returnedInts = GetIntsArrayInFile(file, "Credits.ints", &returnedIntsLen);
if (returnedInts)
{
  for (int i = 0; i < returnedIntsLen; i  )
  {
  	printf("%d, ", returnedInts[i]);
  }
  free(returnedInts);
}

Get a float array in file:

int returnedFloatsLen = 0;
float* returnedFloats = GetFloatsArrayInFile(file, "Credits.floats", &returnedFloatsLen);
if (returnedFloats)
{
  for (int i = 0; i < returnedFloatsLen; i  )
  {
  	printf("%f, ", returnedFloats[i]);
  }
  free(returnedFloats);
}

Get a double array in file:

int returnedDoublesLen = 0;
double* returnedDoubles = GetDoublesArrayInFile(file, "Credits.doubles", &returnedDoublesLen);
if (returnedDoubles)
{
	for (int i = 0; i < returnedDoublesLen; i  )
	{
		printf("%lf, ", returnedDoubles[i]);
	}
	free(returnedDoubles);
}

Get a string array in file:

int size;
char** returnedStrings = GetStringArrayInFile(file, "Credits.strings", &size);
if (returnedStrings)
{
	for (int i = 0; i < size; i  )
	{
		printf("%s\n", returnedStrings[i]);
		free(returnedStrings[i]);
	}
	free(returnedStrings);
}

NOTE: You need to open and close a file to do that

Example of file.txt:

#Credits
backSprite: "backSpriteCredits.png"
message: "\"Wesh les gens !\""
int: 5
float: 5.555
double: 15.555555555
ints: [1, 2, 3, 4, 5]
floats: [1.9, 2.8, 3.7, 4.6, 5.5]
doubles: [1.12345678910, 2.12345678910, 3.12345678910, 4.12345678910, 5.12345678910]
strings: ["\"Hello world !\"", "I'm ", "a ", "string ", "array."]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages