{"id":9556,"date":"2022-09-19T12:55:58","date_gmt":"2022-09-19T07:25:58","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/"},"modified":"2022-09-19T12:55:58","modified_gmt":"2022-09-19T07:25:58","slug":"solved-basic-rename-statementss-unusal-behaviour-in-c","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/","title":{"rendered":"[Solved] Basic rename statements&#8217;s unusal behaviour in c"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-56313997\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"56313997\" data-parentid=\"45524284\" data-score=\"0\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>Here is the complete code. The renaming problem is gone. The renaming problem occurs if the the file is open or doesn&#8217;t exists in the directory.<\/p>\n<pre><code>#include&lt;stdio.h&gt;\n#include &lt;string.h&gt;\n#include &lt;stdlib.h&gt;\n#include&lt;inttypes.h&gt;\n#include&lt;windows.h&gt;\n\n\/\/Variable Declarations\nstruct record_stu st;\nFILE *fp,*fp_tmp,*fp1,*f,*f1;\nunsigned long long int id;\nchar Selected_Exam[255],subject[255],Exam[255],year[255];\nchar semester[255],Dept_name[255],username[55],username_log[55], pass1[8]; \nchar pass2[8],pasword[10],usrname[10],ch,pasword1[10];\nchar usrname1[10],Course_Code[255],ss[255],s1[255] = \"\";\nchar s2[255] = \"\",Gained_Letter_Grade[255],filename,lg,ct[255],cc[255],ct1[255];\nint Course_Code_Number,i,gm,j=0,z,n=0,i,cs=0;\nint flag=0,records=0,x[12],Dept_code,Gained_Mark,p=0;\nfloat Gained_Grade_Point,Credit_Completed,gp,cd,tgp=0,tcd=0,cgpa=0,sgpa,pgp,ccr;\n\nconst char* charString1 = \"Exam\";\nconst char* charString2 = \"Student_ID\";\nconst char* charString3 = \"Department Name\";\nconst char* charString4 = \"Course Code\";\nconst char* charString5 = \"Year\";\nconst char* charString6 = \"Semester\";\nconst char* charString7 = \"Letter Grade\";\nconst char* charString8 = \"Gained Mark\";\nconst char* charString9 = \"Grade Point\";\nconst char* charString10 = \"Credit Completed\";\nconst char* charString11 = \"Course Title\";\nconst char* charString12 = \"Yes\";\nconst char* charString13 = \"No\";\n\nstruct record_stu\n{\n unsigned long long int id;\n float sgpa;\n int gm;\n float gp,cd,ccr;\n char Exam[255],subject[255],semester[255],year[255];\n char Dept_name[255],Exam1[255],lg[255],ct[255],cc[255],ct1[255];\n};\n\/\/Variable Declarations    \nmain()\n{\n \/\/File open command\n fp = fopen(\"Student - Copy.txt\",\"r\");\n fp_tmp = fopen(\"temp.txt\",\"w\");\n \/\/File Open Command\n\n if(!(fp)) \/\/File Open Error Detection\n {\n   printf(\"An Error has occurred.File can't be Found\\n\");\n }\n else \/\/Searching for the record to delete\n {\n   fclose(fp_tmp);\n   fclose(fp);\n   printf(\"File Found.\\n\");\n   rewind(fp);\n   printf(\"\\nEnter Student ID: \");\n   scanf(\"%\"PRIu64\"\",&amp;id);\n   printf(\"\\nEnter Course Code:\");\n   scanf(\"%s\",subject);\n\n   fp = fopen(\"Student - Copy.txt\",\"r\");\n   fp_tmp = fopen(\"temp.txt\",\"w\");\n   while (fscanf(fp,\"%s %\"PRIu64\"%s%s%s%s%s%d%f%f%s\\n\",st.Exam1,&amp;st.id,st.Dept_name,st.subject,st.year,st.semester,&amp;st.lg,&amp;st.gm,&amp;st.gp,&amp;ccr,&amp;st.ct1) != EOF)\n      {\n        records++;\n        if(st.id==id &amp;&amp; strcmp(st.subject,subject)==0)\n        {\n          printf(\"Do you want to delete the record?(Yes(1)\/No(2))\\nEnter Your Choice: \");\n          scanf(\"%d\",&amp;z);\n          printf(\"Confirmation Code = %d\\n\",z);\n          if(z==1)\n          {\n             printf(\"Do you want to confirm deletion of the record?(Yes(1)\/No(2))\\nEnter Your Choice: \");\n              scanf(\"%d\",&amp;p);\n          }\n        }\n        else\n        {\n             fprintf(fp_tmp,\"%s %11\"PRIu64\"\\t%s\\t%s\\t%3s\\t%3s\\t%s\\t%d\\t%3.2f\\t%f\\t%s\\n\",st.Exam1,st.id,st.Dept_name,st.subject,st.year,st.semester,st.lg,st.gm,st.gp,ccr,st.ct1);\n        }\n        }\n\n\n    }\/\/Searching for the record to delete\n\n    \/\/Actual Delete operation by renaming the temporary file to the source file name\n    if(p==1)\n    {\n        printf(\"Confirmation Code = %d\\n\",p);\n        fclose(fp_tmp);\n        fclose(fp);\n        remove(\"Student - Copy.txt\");\n        if(rename(\"temp.txt\",\"Student - Copy.txt\")==0)\n            printf(\"Delete Successful\");\n    }\n    else\n    {\n        fclose(fp_tmp);\n        fclose(fp);\n        printf(\"Delete Unsuccessful\");\n        remove(\"temp.txt\");\n    }\n    \/\/Actual Delete operation by renaming the temporary file to the source file name\n}\n<\/code><\/pre>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">1<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Basic rename statements&#8217;s unusal behaviour in c <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] Here is the complete code. The renaming problem is gone. The renaming problem occurs if the the file is open or doesn&#8217;t exists in the directory. #include&lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;stdlib.h&gt; #include&lt;inttypes.h&gt; #include&lt;windows.h&gt; \/\/Variable Declarations struct record_stu st; FILE *fp,*fp_tmp,*fp1,*f,*f1; unsigned long long int id; char Selected_Exam[255],subject[255],Exam[255],year[255]; char semester[255],Dept_name[255],username[55],username_log[55], pass1[8]; char pass2[8],pasword[10],usrname[10],ch,pasword1[10]; char usrname1[10],Course_Code[255],ss[255],s1[255] &#8230; <a title=\"[Solved] Basic rename statements&#8217;s unusal behaviour in c\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/\" aria-label=\"More on [Solved] Basic rename statements&#8217;s unusal behaviour in c\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[324],"class_list":["post-9556","post","type-post","status-publish","format-standard","hentry","category-solved","tag-c"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Basic rename statements&#039;s unusal behaviour in c - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Basic rename statements&#039;s unusal behaviour in c - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] Here is the complete code. The renaming problem is gone. The renaming problem occurs if the the file is open or doesn&#8217;t exists in the directory. #include&lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;stdlib.h&gt; #include&lt;inttypes.h&gt; #include&lt;windows.h&gt; \/\/Variable Declarations struct record_stu st; FILE *fp,*fp_tmp,*fp1,*f,*f1; unsigned long long int id; char Selected_Exam[255],subject[255],Exam[255],year[255]; char semester[255],Dept_name[255],username[55],username_log[55], pass1[8]; char pass2[8],pasword[10],usrname[10],ch,pasword1[10]; char usrname1[10],Course_Code[255],ss[255],s1[255] ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-19T07:25:58+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Basic rename statements&#8217;s unusal behaviour in c\",\"datePublished\":\"2022-09-19T07:25:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/\"},\"wordCount\":47,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"c++\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/\",\"name\":\"[Solved] Basic rename statements's unusal behaviour in c - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-09-19T07:25:58+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Basic rename statements&#8217;s unusal behaviour in c\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Basic rename statements's unusal behaviour in c - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Basic rename statements's unusal behaviour in c - JassWeb","og_description":"[ad_1] Here is the complete code. The renaming problem is gone. The renaming problem occurs if the the file is open or doesn&#8217;t exists in the directory. #include&lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;stdlib.h&gt; #include&lt;inttypes.h&gt; #include&lt;windows.h&gt; \/\/Variable Declarations struct record_stu st; FILE *fp,*fp_tmp,*fp1,*f,*f1; unsigned long long int id; char Selected_Exam[255],subject[255],Exam[255],year[255]; char semester[255],Dept_name[255],username[55],username_log[55], pass1[8]; char pass2[8],pasword[10],usrname[10],ch,pasword1[10]; char usrname1[10],Course_Code[255],ss[255],s1[255] ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/","og_site_name":"JassWeb","article_published_time":"2022-09-19T07:25:58+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Basic rename statements&#8217;s unusal behaviour in c","datePublished":"2022-09-19T07:25:58+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/"},"wordCount":47,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["c++"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/","url":"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/","name":"[Solved] Basic rename statements's unusal behaviour in c - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-09-19T07:25:58+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-basic-rename-statementss-unusal-behaviour-in-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Basic rename statements&#8217;s unusal behaviour in c"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/9556","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=9556"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/9556\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=9556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=9556"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=9556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}