{"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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","_uag_custom_page_level_css":"","footnotes":""},"class_list":["post-3882","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Les fichiers FILE - workboot<\/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:\/\/workboot.fr\/ciela\/les-fichiers-file\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Les fichiers FILE - workboot\" \/>\n<meta property=\"og:description\" content=\"Fichier en langage C fopen , fclose , fprintf , fscanf , fputc , fgetc , fgets , fread , fwrite, fputc , fputs. Cr\u00e9ation d&rsquo;un fichier ( en \u00e9criture [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/workboot.fr\/ciela\/les-fichiers-file\/\" \/>\n<meta property=\"og:site_name\" content=\"workboot\" \/>\n<meta property=\"article:modified_time\" content=\"2025-09-05T10:03:12+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Dur\u00e9e de lecture estim\u00e9e\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/les-fichiers-file\\\/\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/les-fichiers-file\\\/\",\"name\":\"Les fichiers FILE - workboot\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#website\"},\"datePublished\":\"2025-09-05T09:58:59+00:00\",\"dateModified\":\"2025-09-05T10:03:12+00:00\",\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/workboot.fr\\\/ciela\\\/les-fichiers-file\\\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#website\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/\",\"name\":\"workboot\",\"description\":\"Open Source, Open Minds \",\"publisher\":{\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#organization\",\"name\":\"workboot\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/logo_ciel-dorian-1.png\",\"contentUrl\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/logo_ciel-dorian-1.png\",\"width\":1024,\"height\":950,\"caption\":\"workboot\"},\"image\":{\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#\\\/schema\\\/logo\\\/image\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Les fichiers FILE - workboot","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:\/\/workboot.fr\/ciela\/les-fichiers-file\/","og_locale":"fr_FR","og_type":"article","og_title":"Les fichiers FILE - workboot","og_description":"Fichier en langage C fopen , fclose , fprintf , fscanf , fputc , fgetc , fgets , fread , fwrite, fputc , fputs. Cr\u00e9ation d&rsquo;un fichier ( en \u00e9criture [&hellip;]","og_url":"https:\/\/workboot.fr\/ciela\/les-fichiers-file\/","og_site_name":"workboot","article_modified_time":"2025-09-05T10:03:12+00:00","twitter_misc":{"Dur\u00e9e de lecture estim\u00e9e":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/workboot.fr\/ciela\/les-fichiers-file\/","url":"https:\/\/workboot.fr\/ciela\/les-fichiers-file\/","name":"Les fichiers FILE - workboot","isPartOf":{"@id":"https:\/\/workboot.fr\/ciela\/#website"},"datePublished":"2025-09-05T09:58:59+00:00","dateModified":"2025-09-05T10:03:12+00:00","inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/workboot.fr\/ciela\/les-fichiers-file\/"]}]},{"@type":"WebSite","@id":"https:\/\/workboot.fr\/ciela\/#website","url":"https:\/\/workboot.fr\/ciela\/","name":"workboot","description":"Open Source, Open Minds ","publisher":{"@id":"https:\/\/workboot.fr\/ciela\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/workboot.fr\/ciela\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Organization","@id":"https:\/\/workboot.fr\/ciela\/#organization","name":"workboot","url":"https:\/\/workboot.fr\/ciela\/","logo":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/workboot.fr\/ciela\/#\/schema\/logo\/image\/","url":"https:\/\/workboot.fr\/ciela\/wp-content\/uploads\/2025\/05\/logo_ciel-dorian-1.png","contentUrl":"https:\/\/workboot.fr\/ciela\/wp-content\/uploads\/2025\/05\/logo_ciel-dorian-1.png","width":1024,"height":950,"caption":"workboot"},"image":{"@id":"https:\/\/workboot.fr\/ciela\/#\/schema\/logo\/image\/"}}]}},"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 [&hellip;]","_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}]}}