{"id":3882,"date":"2025-09-05T10:58:59","date_gmt":"2025-09-05T09:58:59","guid":{"rendered":"https:\/\/workboot.fr\/ciela\/?page_id=3882"},"modified":"2025-09-05T11:03:12","modified_gmt":"2025-09-05T10:03:12","slug":"les-fichiers-file","status":"publish","type":"page","link":"https:\/\/workboot.fr\/ciela\/les-fichiers-file\/","title":{"rendered":"Les fichiers FILE"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Fichier en langage C<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>fopen , fclose , fprintf , fscanf , fputc , fgetc , fgets , fread , fwrite, fputc , fputs.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h.p_vgoidcgHaFAE_l\">Cr\u00e9ation d&rsquo;un fichier ( en \u00e9criture )<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Le plus simple est de tester , un code qui va fabriquer un fichier dans lequel on glisse le mot Bonjour&nbsp;<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/* Cr\u00e9ation de fichier , \u00e9criture*\/\n#include &lt;stdio.h>\n#include &lt;stdlib.h>\n\nint main(int argc, char** argv)\n{\nFILE * fichier;     \/* Type fichier FILE  *\/\nif(argc!=2)\n{\n    printf(\"vous n'avez pas entr\u00e9 de parametre \\n\");\n    exit(EXIT_FAILURE);\n}\n\nfichier = fopen(\"snir1.txt\",\"w\"); \/* on ouvre le fichier en ecriture *\/\n    if (fichier == NULL)\n    {\n        printf(\" Je n'ai pas reussi a ouvrir le fichier \\n\");\n        exit(EXIT_FAILURE);  \/*on sort du programme erreur .. d'ouverture *\/\n    }\n    fprintf(fichier,\"Hello World! %s \\n\",argv[1]); \/* j'ecris dans le fichier  *\/\n    fclose(fichier);  \/* je ferme le fichier *\/\n    return EXIT_SUCCESS;\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h.p_dhLlZJVmaFAu_l\">Lecture d&rsquo;un fichier&nbsp;<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Et voila le code de son r\u00e9ciproque<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;stdio.h>\n#include &lt;stdlib.h>\nint main (int argc, char **argv)\n{\nFILE * fichier;\nchar carac;\nfichier = fopen(\"fichier.txt\",\"r\");\nif (fichier == NULL )\n                                {\n                                printf( \" Erreur a l'ouverture ! \\n\");\n                                return EXIT_FAILURE;\n                                }\ncarac = fgetc (fichier);\nprintf (\"%c\\n\",(char)carac);\nfclose (fichier);\nreturn EXIT_SUCCESS;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Ici carac r\u00e9cup\u00e8re le premier caract\u00e8re du fichier , dans notre cas le &lsquo;B&rsquo; de Bonjour<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">on&nbsp;<strong>cast<\/strong>&nbsp;carac pour que le printf re\u00e7oive bien comme attendu un char (8bits) mais effectivement fgetc renvoi un entier&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">qui peut etre positif et negatif .. si il fait -1 c&rsquo;est qu&rsquo;aucun caract\u00e8re n&rsquo;as \u00e9t\u00e9 lu .<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">EOF est d\u00e9fini a -1 (dans stdio.h )<\/p>\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary>extrait de\u00a0<strong>stdio.h<\/strong><\/summary>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/* End of file character.\n   Some things throughout the library rely on this being -1.  *\/\n#ifndef EOF\n# define EOF (-1)\n#endif<\/pre>\n<\/details>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>EOF<\/strong> : End o FILE<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fichier en langage C fopen , fclose , fprintf , fscanf , fputc , fgetc , fgets , fread , fwrite, fputc , fputs. Cr\u00e9ation d&rsquo;un fichier ( en \u00e9criture ) Le plus simple est de tester , un code qui va fabriquer un fichier dans lequel on glisse le mot Bonjour&nbsp; Lecture d&rsquo;un fichier&nbsp; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_uag_custom_page_level_css":"","footnotes":""},"class_list":["post-3882","page","type-page","status-publish","hentry"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"admin","author_link":"https:\/\/workboot.fr\/ciela\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"Fichier en langage C fopen , fclose , fprintf , fscanf , fputc , fgetc , fgets , fread , fwrite, fputc , fputs. Cr\u00e9ation d&rsquo;un fichier ( en \u00e9criture ) Le plus simple est de tester , un code qui va fabriquer un fichier dans lequel on glisse le mot Bonjour&nbsp; Lecture d&rsquo;un fichier&nbsp;\u2026","_links":{"self":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/3882","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/comments?post=3882"}],"version-history":[{"count":5,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/3882\/revisions"}],"predecessor-version":[{"id":3890,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/3882\/revisions\/3890"}],"wp:attachment":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/media?parent=3882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}