		
		{"id":18424,"date":"2024-06-10T09:50:07","date_gmt":"2024-06-10T09:50:07","guid":{"rendered":"http:\/\/localhost\/netizens_12_aug\/?p=12064"},"modified":"2024-06-10T09:50:07","modified_gmt":"2024-06-10T09:50:07","slug":"fgets-c","status":"publish","type":"post","link":"https:\/\/netizens.netizens.dev\/br\/blog\/fgets-c\/","title":{"rendered":"fgets() in C: A Beginner\u2019s Tutorial"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Reading input safely is an essential part of C programming. While functions like <\/span><span style=\"font-weight: 400;\">gets()<\/span><span style=\"font-weight: 400;\"> exist, they can be dangerous because they don\u2019t check the buffer size. The safer alternative is <\/span><span style=\"font-weight: 400;\">fgets()<\/span><span style=\"font-weight: 400;\">, which allows you to read strings from the user or a file safely.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In this tutorial, you\u2019ll learn how <\/span><span style=\"font-weight: 400;\">fgets()<\/span><span style=\"font-weight: 400;\"> works, its syntax, examples, and outputs.<\/span><\/p>\n<h2>What is fgets()?<\/h2>\n<p><span style=\"font-weight: 400;\">fgets()<\/span><span style=\"font-weight: 400;\"> is a standard function in <\/span><span style=\"font-weight: 400;\">&lt;stdio.h&gt;<\/span><span style=\"font-weight: 400;\"> used to read lines of text into a string. It stops reading when:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">A newline character (<\/span><span style=\"font-weight: 400;\">\\n<\/span><span style=\"font-weight: 400;\">) is encountered.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The specified number of characters has been read.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The end-of-file (EOF) is reached.<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Because you can specify the buffer size, it prevents buffer overflow\u2014something <\/span><span style=\"font-weight: 400;\">gets()<\/span><span style=\"font-weight: 400;\"> cannot do.<\/span><\/p>\n<h2>Syntax<\/h2>\n<pre style=\"background: #fdfdfd; color: #333; padding: 1px 14px 14px 14px; border-radius: 6px; font-size: 18px; line-height: 24px; overflow-x: auto; margin: 10px 0; border: 2px solid #eee;\"><code>\n<span style=\"color: #777;\">\/\/ Syntax of fgets() in C<\/span>\n<span style=\"color: #008080; font-weight: bold;\">char<\/span> *<span style=\"color: #003366; font-weight: bold;\">fgets<\/span>(<span style=\"color: #008080; font-weight: bold;\">char<\/span> *str, <span style=\"color: #008080; font-weight: bold;\">int<\/span> n, FILE *stream);\n<\/code><\/pre>\n<p><b>Parameters:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">str<\/span><span style=\"font-weight: 400;\">: Array to store the input.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">n<\/span><span style=\"font-weight: 400;\">: Maximum number of characters to read (including <\/span><span style=\"font-weight: 400;\">\\0<\/span><span style=\"font-weight: 400;\">).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">stream<\/span><span style=\"font-weight: 400;\">: Input source (<\/span><span style=\"font-weight: 400;\">stdin<\/span><span style=\"font-weight: 400;\"> for keyboard or a file pointer).<\/span><\/li>\n<\/ul>\n<p><b>Return Value:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Returns <\/span><span style=\"font-weight: 400;\">str<\/span><span style=\"font-weight: 400;\"> if successful.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Returns <\/span><span style=\"font-weight: 400;\">NULL<\/span><span style=\"font-weight: 400;\"> if an error occurs or EOF is reached.<\/span><\/li>\n<\/ul>\n<h2>Example 1: Reading Input from the User<\/h2>\n<pre style=\"background: #fdfdfd; color: #333; padding: 1px 14px 14px 14px; border-radius: 6px; font-size: 18px; line-height: 24px; overflow-x: auto; margin: 10px 0; border: 2px solid #eee;\"><code>\n<span style=\"color: #777;\">\/\/ Example: Reading input using fgets()<\/span>\n<span style=\"color: #003366; font-weight: bold;\">#include<\/span> &lt;stdio.h&gt;\n\n<span style=\"color: #008080; font-weight: bold;\">int<\/span> main() {\n    <span style=\"color: #008080; font-weight: bold;\">char<\/span> name[50];\n\n    printf(<span style=\"color: #a31515;\">\"Enter your name: \"<\/span>);\n\n    fgets(name, <span style=\"color: #00008b; font-weight: bold;\">sizeof<\/span>(name), stdin);\n\n    printf(<span style=\"color: #a31515;\">\"Hello, %s\"<\/span>, name);\n\n    <span style=\"color: #008080; font-weight: bold;\">return<\/span> 0;\n}\n<\/code><\/pre>\n<p><b>Sample Output 1:<\/b><\/p>\n<div style=\"background-color: #e0e0e0; padding: 20px 20px; border-radius: 6px; margin-bottom: 5px;\">Enter your name:<br \/>\nNetizensHello, Netizens<\/div>\n<p><b>Explanation:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">fgets()<\/span><span style=\"font-weight: 400;\"> reads up to 49 characters and adds a null terminator.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">If the input is shorter than the buffer, it stops at the newline.<\/span><\/li>\n<\/ul>\n<h2>Example 2: Removing the Newline Character<\/h2>\n<p><span style=\"font-weight: 400;\">fgets()<\/span><span style=\"font-weight: 400;\"> keeps the newline (<\/span><span style=\"font-weight: 400;\">\\n<\/span><span style=\"font-weight: 400;\">) if the user presses Enter. To remove it:<\/span><\/p>\n<pre style=\"background: #fdfdfd; color: #333; padding: 1px 14px 14px 14px; border-radius: 6px; font-size: 18px; line-height: 24px; overflow-x: auto; margin: 10px 0; border: 2px solid #eee;\"><code>\n<span style=\"color: #777;\">\/\/ Example: fgets() with newline removal<\/span>\n<span style=\"color: #003366; font-weight: bold;\">#include<\/span> &lt;stdio.h&gt;\n<span style=\"color: #003366; font-weight: bold;\">#include<\/span> &lt;string.h&gt;\n\n<span style=\"color: #008080; font-weight: bold;\">int<\/span> main() {\n    <span style=\"color: #008080; font-weight: bold;\">char<\/span> name[50];\n\n    printf(<span style=\"color: #a31515;\">\"Enter your name: \"<\/span>);\n    fgets(name, <span style=\"color: #00008b; font-weight: bold;\">sizeof<\/span>(name), stdin);\n\n    <span style=\"color: #777;\">\/\/ Remove newline character if present<\/span>\n    name[strcspn(name, <span style=\"color: #a31515;\">\"\\n\"<\/span>)] = <span style=\"color: #a31515;\">'\\0'<\/span>;\n\n    printf(<span style=\"color: #a31515;\">\"Hello, %s\"<\/span>, name);\n\n    <span style=\"color: #008080; font-weight: bold;\">return<\/span> 0;\n}\n<\/code><\/pre>\n<p><b>Sample Output 2:<\/b><\/p>\n<div style=\"background-color: #e0e0e0; padding: 20px 20px; border-radius: 6px; margin-bottom: 5px;\">Enter your name:<br \/>\nNetizensHello, Netizens<\/div>\n<p><b>Explanation:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">strcspn(name, &#8220;\\n&#8221;)<\/span><span style=\"font-weight: 400;\"> finds the newline position and replaces it with <\/span><span style=\"font-weight: 400;\">\\0<\/span><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The string is now clean for printing or comparisons.<\/span><\/li>\n<\/ul>\n<h2>Example 3: Reading a Limited Number of Characters<\/h2>\n<pre style=\"background: #fdfdfd; color: #333; padding: 1px 14px 14px 14px; border-radius: 6px; font-size: 18px; line-height: 24px; overflow-x: auto; margin: 10px 0; border: 2px solid #eee;\"><code>\n<span style=\"color: #777;\">\/\/ Example: fgets() with limited buffer size<\/span>\n<span style=\"color: #003366; font-weight: bold;\">#include<\/span> &lt;stdio.h&gt;\n\n<span style=\"color: #008080; font-weight: bold;\">int<\/span> main() {\n    <span style=\"color: #008080; font-weight: bold;\">char<\/span> buffer[10];\n\n    printf(<span style=\"color: #a31515;\">\"Enter a string: \"<\/span>);\n    fgets(buffer, <span style=\"color: #00008b; font-weight: bold;\">sizeof<\/span>(buffer), stdin);\n\n    printf(<span style=\"color: #a31515;\">\"You entered: %s\"<\/span>, buffer);\n\n    <span style=\"color: #008080; font-weight: bold;\">return<\/span> 0;\n}\n<\/code><\/pre>\n<p><b>Sample Output 3:<\/b><\/p>\n<div style=\"background-color: #e0e0e0; padding: 20px 20px; border-radius: 6px; margin-bottom: 5px;\">\n<p>Enter a string: Hello World<\/p>\n<p>You entered: Hello Wor<\/p>\n<\/div>\n<p><b>Explanation:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The buffer size is 10, so <\/span><span style=\"font-weight: 400;\">fgets()<\/span><span style=\"font-weight: 400;\"> reads 9 characters and adds the null terminator.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The newline character is included if space allows.<\/span><\/li>\n<\/ul>\n<h2>Example 4: Reading from a File<\/h2>\n<pre style=\"background: #fdfdfd; color: #333; padding: 1px 14px 14px 14px; border-radius: 6px; font-size: 18px; line-height: 24px; overflow-x: auto; margin: 10px 0; border: 2px solid #eee;\"><code>\n<span style=\"color: #777;\">\/\/ Example: fgets() reading from a file<\/span>\n<span style=\"color: #003366; font-weight: bold;\">#include<\/span> &lt;stdio.h&gt;\n\n<span style=\"color: #008080; font-weight: bold;\">int<\/span> main() {\n\n    <span style=\"color: #008080; font-weight: bold;\">FILE<\/span> *file = fopen(<span style=\"color: #a31515;\">\"example.txt\"<\/span>, <span style=\"color: #a31515;\">\"r\"<\/span>);\n    <span style=\"color: #008080; font-weight: bold;\">char<\/span> line[50];\n\n    <span style=\"color: #00008b; font-weight: bold;\">if<\/span>(file) {\n        <span style=\"color: #00008b; font-weight: bold;\">while<\/span>(fgets(line, <span style=\"color: #00008b; font-weight: bold;\">sizeof<\/span>(line), file)) {\n            printf(<span style=\"color: #a31515;\">\"%s\"<\/span>, line);\n        }\n        fclose(file);\n    } <span style=\"color: #00008b; font-weight: bold;\">else<\/span> {\n        printf(<span style=\"color: #a31515;\">\"Could not open the file.\\n\"<\/span>);\n    }\n\n    <span style=\"color: #008080; font-weight: bold;\">return<\/span> 0;\n}\n<\/code><\/pre>\n<p><span style=\"font-weight: 400;\">Assume <\/span><span style=\"font-weight: 400;\">example.txt<\/span><span style=\"font-weight: 400;\"> contains:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Hello World<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C programming is fun<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fgets() is safe<\/span><\/p>\n<p><b>Sample Output 4:<\/b><\/p>\n<div style=\"background-color: #e0e0e0; padding: 20px 20px; border-radius: 6px; margin-bottom: 5px;\">Hello World<br \/>\nC programming is fun<br \/>\nfgets() is safe<\/div>\n<p><b>Explanation:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Reads one line at a time, up to the buffer size.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Safe and avoids buffer overflow when reading files.<\/span><\/li>\n<\/ul>\n<h2>gets() vs fgets()<\/h2>\n<table style=\"width: 100%; border-collapse: collapse; box-shadow: 0 2px 8px rgba(0,0,0,0.1);\">\n<thead>\n<tr style=\"background-color: #333333; color: #fff;\">\n<th style=\"padding: 12px; border: 1px solid #ddd;\">Feature<\/th>\n<th style=\"padding: 12px; border: 1px solid #ddd;\">gets()<\/th>\n<th style=\"padding: 12px; border: 1px solid #ddd;\">fgets()<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background-color: #f9f9f9;\">\n<td style=\"padding: 10px; border: 1px solid #ddd;\">Buffer Control<\/td>\n<td style=\"padding: 10px; border: 1px solid #ddd;\">No control \u2192 unsafe<\/td>\n<td style=\"padding: 10px; border: 1px solid #ddd; color: green;\">Can set buffer size \u2192 safe<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px; border: 1px solid #ddd;\">Newline Handling<\/td>\n<td style=\"padding: 10px; border: 1px solid #ddd;\">Removes newline<\/td>\n<td style=\"padding: 10px; border: 1px solid #ddd;\">Keeps newline<\/td>\n<\/tr>\n<tr style=\"background-color: #f9f9f9;\">\n<td style=\"padding: 10px; border: 1px solid #ddd;\">Input Source<\/td>\n<td style=\"padding: 10px; border: 1px solid #ddd;\">Keyboard only<\/td>\n<td style=\"padding: 10px; border: 1px solid #ddd;\">Keyboard or file<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px; border: 1px solid #ddd;\">Error Handling<\/td>\n<td style=\"padding: 10px; border: 1px solid #ddd; color: red;\">Cannot detect errors<\/td>\n<td style=\"padding: 10px; border: 1px solid #ddd; color: green;\">Returns NULL on error or EOF<\/td>\n<\/tr>\n<tr style=\"background-color: #f9f9f9;\">\n<td style=\"padding: 10px; border: 1px solid #ddd;\">Status<\/td>\n<td style=\"padding: 10px; border: 1px solid #ddd; color: red;\">Deprecated in modern C<\/td>\n<td style=\"padding: 10px; border: 1px solid #ddd; color: green;\">Recommended and widely used<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Tips for Using fgets()<\/h2>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Use a large enough buffer for input.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Remove the newline if needed.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Don\u2019t mix <\/span><span style=\"font-weight: 400;\">fgets()<\/span><span style=\"font-weight: 400;\"> with <\/span><span style=\"font-weight: 400;\">scanf()<\/span><span style=\"font-weight: 400;\"> carelessly; leftover input can cause issues.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Use it for file reading to safely read line by line.<\/span><\/li>\n<\/ol>\n<p>Also Read: <a href=\"https:\/\/netizens.netizens.dev\/br\/blog\/how-to-get-the-length-of-a-string-in-python-stack-overflow\/\" target=\"_blank\" rel=\"noopener\">How to get the length of a string in python<\/a><\/p>\n<h2>Summary<\/h2>\n<p><span style=\"font-weight: 400;\">fgets()<\/span><span style=\"font-weight: 400;\"> is a safe, reliable, and flexible way to read strings in C. It works for both keyboard input and file reading, preventing common mistakes like buffer overflow.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">By practicing with <\/span><span style=\"font-weight: 400;\">fgets()<\/span><span style=\"font-weight: 400;\">, you\u2019ll be able to handle user input safely and write more robust C programs.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">FAQs<\/span><\/h2>\n<div style=\"margin: 10px 0; line-height: 33px;\">\n<div style=\"padding: 10px 0; border-bottom: 1px solid #ddd;\">\n<h3 style=\"margin: 0 0 6px;\">1. What is the difference between gets() and fgets() in C?<\/h3>\n<p style=\"margin: 0;\">gets() is unsafe as it doesn\u2019t check the buffer size, which may cause a buffer overflow. fgets() is safe because you can set the buffer size.<\/p>\n<\/div>\n<div style=\"padding: 10px 0; border-bottom: 1px solid #ddd;\">\n<h3 style=\"margin: 0 0 6px;\">2. Does fgets() include the newline character?<\/h3>\n<p style=\"margin: 0;\">Yes. If there\u2019s enough space in the buffer, fgets() keeps the newline (\\n). You can remove it manually using strcspn() or other methods.<\/p>\n<\/div>\n<div style=\"padding: 10px 0; border-bottom: 1px solid #ddd;\">\n<h3 style=\"margin: 0 0 6px;\">3. Can fgets() read input from a file?<\/h3>\n<p style=\"margin: 0;\">Yes. fgets() can read strings both from stdin (keyboard input) and from a file pointer. It\u2019s commonly used to read file data line by line.<\/p>\n<\/div>\n<div style=\"padding: 10px 0;\">\n<h3 style=\"margin: 0 0 6px;\">4. What happens if I enter more characters than the buffer size in fgets()?<\/h3>\n<p style=\"margin: 0;\">fgets() only reads up to n-1 characters and adds a null terminator. Extra characters remain in the input buffer until read again.<\/p>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Reading input safely is an essential part of C programming. While functions like gets() exist, they can be dangerous because they don\u2019t check the buffer size. The safer alternative is fgets(), which allows you to read strings from the user or a file safely. In this tutorial, you\u2019ll learn how fgets() works, its syntax, examples, [&hellip;]<\/p>","protected":false},"author":2,"featured_media":18773,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[176,1011],"tags":[1833,1834],"class_list":["post-18424","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-information","category-other","tag-fgets-c","tag-fgets-c-programming"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>fgets() in C: A Beginner\u2019s Tutorial | Netizens Technologies<\/title>\n<meta name=\"description\" content=\"Learn how to use fgets() in C safely. This tutorial covers syntax, examples, file input, removing newline characters, and tips for beginners.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/netizens.netizens.dev\/br\/blog\/fgets-c\/\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"fgets() in C: A Beginner\u2019s Tutorial | Netizens Technologies\" \/>\n<meta property=\"og:description\" content=\"Learn how to use fgets() in C safely. This tutorial covers syntax, examples, file input, removing newline characters, and tips for beginners.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/netizens.netizens.dev\/br\/blog\/fgets-c\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-06-10T09:50:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/netizens.netizens.dev\/wp-content\/uploads\/2024\/06\/fgets-c.png\" \/>\n\t<meta property=\"og:image:width\" content=\"645\" \/>\n\t<meta property=\"og:image:height\" content=\"360\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. tempo de leitura\" \/>\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\":\"WebPage\",\"@id\":\"https:\/\/netizens.netizens.dev\/blog\/fgets-c\/\",\"url\":\"https:\/\/netizens.netizens.dev\/blog\/fgets-c\/\",\"name\":\"fgets() in C: A Beginner\u2019s Tutorial | Netizens Technologies\",\"isPartOf\":{\"@id\":\"https:\/\/netizens.netizens.dev\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/netizens.netizens.dev\/blog\/fgets-c\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/netizens.netizens.dev\/blog\/fgets-c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/netizens.netizens.dev\/wp-content\/uploads\/2024\/06\/fgets-c.png\",\"datePublished\":\"2024-06-10T09:50:07+00:00\",\"dateModified\":\"2024-06-10T09:50:07+00:00\",\"author\":{\"@id\":\"https:\/\/netizens.netizens.dev\/#\/schema\/person\/5db7227e686a10a4126a2c19b8b70517\"},\"description\":\"Learn how to use fgets() in C safely. This tutorial covers syntax, examples, file input, removing newline characters, and tips for beginners.\",\"breadcrumb\":{\"@id\":\"https:\/\/netizens.netizens.dev\/blog\/fgets-c\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/netizens.netizens.dev\/blog\/fgets-c\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/netizens.netizens.dev\/blog\/fgets-c\/#primaryimage\",\"url\":\"https:\/\/netizens.netizens.dev\/wp-content\/uploads\/2024\/06\/fgets-c.png\",\"contentUrl\":\"https:\/\/netizens.netizens.dev\/wp-content\/uploads\/2024\/06\/fgets-c.png\",\"width\":645,\"height\":360,\"caption\":\"Fgets c\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/netizens.netizens.dev\/blog\/fgets-c\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/netizens.netizens.dev\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"fgets() in C: A Beginner\u2019s Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/netizens.netizens.dev\/#website\",\"url\":\"https:\/\/netizens.netizens.dev\/\",\"name\":\"\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/netizens.netizens.dev\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"pt-BR\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/netizens.netizens.dev\/#\/schema\/person\/5db7227e686a10a4126a2c19b8b70517\",\"name\":\"admin admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/netizens.netizens.dev\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b0f87bbe7cdbfbd534a40fea7d9d02021e6d3772c3949940e8de2e3df278fb2f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b0f87bbe7cdbfbd534a40fea7d9d02021e6d3772c3949940e8de2e3df278fb2f?s=96&d=mm&r=g\",\"caption\":\"admin admin\"},\"sameAs\":[\"https:\/\/netizens.netizens.dev\"],\"url\":\"https:\/\/netizens.netizens.dev\/br\/blog\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"fgets() in C: A Beginner\u2019s Tutorial | Netizens Technologies","description":"Learn how to use fgets() in C safely. This tutorial covers syntax, examples, file input, removing newline characters, and tips for beginners.","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:\/\/netizens.netizens.dev\/br\/blog\/fgets-c\/","og_locale":"pt_BR","og_type":"article","og_title":"fgets() in C: A Beginner\u2019s Tutorial | Netizens Technologies","og_description":"Learn how to use fgets() in C safely. This tutorial covers syntax, examples, file input, removing newline characters, and tips for beginners.","og_url":"https:\/\/netizens.netizens.dev\/br\/blog\/fgets-c\/","article_published_time":"2024-06-10T09:50:07+00:00","og_image":[{"width":645,"height":360,"url":"https:\/\/netizens.netizens.dev\/wp-content\/uploads\/2024\/06\/fgets-c.png","type":"image\/png"}],"author":"admin admin","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"admin admin","Est. tempo de leitura":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/netizens.netizens.dev\/blog\/fgets-c\/","url":"https:\/\/netizens.netizens.dev\/blog\/fgets-c\/","name":"fgets() in C: A Beginner\u2019s Tutorial | Netizens Technologies","isPartOf":{"@id":"https:\/\/netizens.netizens.dev\/#website"},"primaryImageOfPage":{"@id":"https:\/\/netizens.netizens.dev\/blog\/fgets-c\/#primaryimage"},"image":{"@id":"https:\/\/netizens.netizens.dev\/blog\/fgets-c\/#primaryimage"},"thumbnailUrl":"https:\/\/netizens.netizens.dev\/wp-content\/uploads\/2024\/06\/fgets-c.png","datePublished":"2024-06-10T09:50:07+00:00","dateModified":"2024-06-10T09:50:07+00:00","author":{"@id":"https:\/\/netizens.netizens.dev\/#\/schema\/person\/5db7227e686a10a4126a2c19b8b70517"},"description":"Learn how to use fgets() in C safely. This tutorial covers syntax, examples, file input, removing newline characters, and tips for beginners.","breadcrumb":{"@id":"https:\/\/netizens.netizens.dev\/blog\/fgets-c\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/netizens.netizens.dev\/blog\/fgets-c\/"]}]},{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/netizens.netizens.dev\/blog\/fgets-c\/#primaryimage","url":"https:\/\/netizens.netizens.dev\/wp-content\/uploads\/2024\/06\/fgets-c.png","contentUrl":"https:\/\/netizens.netizens.dev\/wp-content\/uploads\/2024\/06\/fgets-c.png","width":645,"height":360,"caption":"Fgets c"},{"@type":"BreadcrumbList","@id":"https:\/\/netizens.netizens.dev\/blog\/fgets-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/netizens.netizens.dev\/"},{"@type":"ListItem","position":2,"name":"fgets() in C: A Beginner\u2019s Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/netizens.netizens.dev\/#website","url":"https:\/\/netizens.netizens.dev\/","name":"","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/netizens.netizens.dev\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"pt-BR"},{"@type":"Person","@id":"https:\/\/netizens.netizens.dev\/#\/schema\/person\/5db7227e686a10a4126a2c19b8b70517","name":"admin admin","image":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/netizens.netizens.dev\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b0f87bbe7cdbfbd534a40fea7d9d02021e6d3772c3949940e8de2e3df278fb2f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b0f87bbe7cdbfbd534a40fea7d9d02021e6d3772c3949940e8de2e3df278fb2f?s=96&d=mm&r=g","caption":"admin admin"},"sameAs":["https:\/\/netizens.netizens.dev"],"url":"https:\/\/netizens.netizens.dev\/br\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/netizens.netizens.dev\/br\/wp-json\/wp\/v2\/posts\/18424","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/netizens.netizens.dev\/br\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/netizens.netizens.dev\/br\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/netizens.netizens.dev\/br\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/netizens.netizens.dev\/br\/wp-json\/wp\/v2\/comments?post=18424"}],"version-history":[{"count":0,"href":"https:\/\/netizens.netizens.dev\/br\/wp-json\/wp\/v2\/posts\/18424\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/netizens.netizens.dev\/br\/wp-json\/wp\/v2\/media\/18773"}],"wp:attachment":[{"href":"https:\/\/netizens.netizens.dev\/br\/wp-json\/wp\/v2\/media?parent=18424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/netizens.netizens.dev\/br\/wp-json\/wp\/v2\/categories?post=18424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/netizens.netizens.dev\/br\/wp-json\/wp\/v2\/tags?post=18424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}