{"id":1347,"date":"2023-03-01T14:44:33","date_gmt":"2023-03-01T14:44:33","guid":{"rendered":"https:\/\/ibex.tech\/c\/?p=1347"},"modified":"2024-04-12T15:44:13","modified_gmt":"2024-04-12T14:44:13","slug":"file-functions","status":"publish","type":"post","link":"https:\/\/ibex.tech\/c\/c\/stream\/file-functions","title":{"rendered":"File functions"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">fopen()<\/h4>\n\n\n\n<p>fopen(const char *filename, const char *access_mode)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/access_mode\n\/\/\t\"r\"  Open a file for reading. The file must exist.\n\/\/\t\"r+\" Open a file for reading and writing. The file must exist.\n\/\/\t\"w\"  Create an empty file for writing. If a file with the same name already exists its content is erased.\n\/\/\t\"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.\n\/\/\t\"a\"  Append to a file. Write operations append data at the end of the file. The file is created if it doesn\u2019t exist.\n\/\/\t\"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\n\/\/\t\t 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\u2019t exist.<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">fseek<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\tif (fseek(File1, (long int)MyOffset, SEEK_SET) != 0)\t\t\t\/\/SEEK_SET=Beginning of file, SEEK_CUR=Current position, SEEK_END=End of file.  Returns 0 if successful, non-zero = failed\n\t{\n\t\t\/\/Failed\n\t}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">ftell &#8211; get current position in file as an int<\/h4>\n\n\n\n<p>long int ftell(FILE *stream)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\tint FileBytePosition = ftell(File1)\n\tif (FileBytePosition == -1)\n\t{\n\t\t\/\/Error\n\n\t}\n\telse if (FileBytePosition == 0)\n\t{\n\t\t\/\/At start of file\n\n\t}<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">fgetpos<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">fsetpos<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">rewind<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">fclose<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">remove<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">rename<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">clearerr<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">feof<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">ferror<\/h4>\n","protected":false},"excerpt":{"rendered":"<p>fopen() fopen(const char *filename, const char *access_mode) fseek ftell &#8211; get current position in file as an int long int ftell(FILE *stream) fgetpos fsetpos rewind fclose remove rename clearerr feof ferror<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[114],"tags":[],"class_list":["post-1347","post","type-post","status-publish","format-standard","hentry","category-stream"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/1347","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/comments?post=1347"}],"version-history":[{"count":12,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/1347\/revisions"}],"predecessor-version":[{"id":1556,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/1347\/revisions\/1556"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/media?parent=1347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/categories?post=1347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/tags?post=1347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}