fopen()

fopen(const char *filename, const char *access_mode)

//access_mode
//	"r"  Open a file for reading. The file must exist.
//	"r+" Open a file for reading and writing. The file must exist.
//	"w"  Create an empty file for writing. If a file with the same name already exists its content is erased.
//	"w+" Create an empty file for writing and reading. If a file with the same name already exists its content is erased before it is opened.
//	"a"  Append to a file. Write operations append data at the end of the file. The file is created if it doesn’t exist.
//	"a+" Open a file for reading and appending. All writing operations are done at the end of the file protecting the previous content from being overwritten. You can
//		 reposition (fseek) the pointer to anywhere in the file for reading, but writing operations will move back to the end of file. The file is created if it doesn’t exist.

fseek

	if (fseek(File1, (long int)MyOffset, SEEK_SET) != 0)			//SEEK_SET=Beginning of file, SEEK_CUR=Current position, SEEK_END=End of file.  Returns 0 if successful, non-zero = failed
	{
		//Failed
	}

ftell – get current position in file as an int

long int ftell(FILE *stream)

	int FileBytePosition = ftell(File1)
	if (FileBytePosition == -1)
	{
		//Error

	}
	else if (FileBytePosition == 0)
	{
		//At start of file

	}

fgetpos

fsetpos

rewind

fclose

remove

rename

clearerr

feof

ferror

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through resources like this. We hope you find it helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support here. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published. Required fields are marked *