{"id":3597,"date":"2024-03-06T11:36:40","date_gmt":"2024-03-06T11:36:40","guid":{"rendered":"https:\/\/www.skillvertex.com\/blog\/?p=3597"},"modified":"2024-03-06T11:36:40","modified_gmt":"2024-03-06T11:36:40","slug":"what-is-the-return-type-of-getchar-fgetc-and-getc","status":"publish","type":"post","link":"https:\/\/www.skillvertex.com\/blog\/what-is-the-return-type-of-getchar-fgetc-and-getc\/","title":{"rendered":"What Is The Return Type Of Getchar(), Fgetc() And Getc() ?"},"content":{"rendered":"\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\" id=\"rank-math-toc\"><p>Table of Contents<\/p><nav><ul><li ><a href=\"#what-is-the-return-type-of-getchar-fgetc-and-getc\">What Is The Return Type Of Getchar(), Fgetc() And Getc() ?<\/a><\/li><li ><a href=\"#faq-what-is-the-return-type-of-getchar-fgetc-and-getc\">FAQ- What Is The Return Type Of Getchar(), Fgetc() And Getc() ?<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-the-return-type-of-getchar-fgetc-and-getc\">What Is The Return Type Of Getchar(), Fgetc() And Getc() ?<\/h2>\n\n\n\n<p>In C, when you use <code>getchar()<\/code>, <code>fgetc()<\/code>, or <code>getc()<\/code>, what you get back is not a character but an integer. So, it&#8217;s a good idea to catch that integer by using an integer-type variable. These functions return the ASCII value of the character you input or read, and using an integer-type variable helps you handle and check for special cases like the end of the file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\nchar ch;  \/* May cause problems *\/  \nwhile ((ch = getchar()) != EOF)  \n{ \n   putchar(ch); \n} <\/code><\/pre>\n\n\n\n<p>This version uses integer to compare the value of getchar().<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int in;   \nwhile ((in = getchar()) != EOF)  \n{ \n   putchar(in); \n} <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"faq-what-is-the-return-type-of-getchar-fgetc-and-getc\">FAQ- What Is The Return Type Of Getchar(), Fgetc() And Getc() ?<\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1700220330978\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q1. What is the return type of Getchar ()?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. The getchar() function obtains a character from stdin. It returns the character that was read in the form of an integer or EOF if an error occurs<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1700220336240\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q2. What is getc () and Getchar () in C?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. In C, there are two ways to read characters: <code>getc()<\/code> and <code>getchar()<\/code>. The key difference is that <code>getc()<\/code> can read from anywhere, not just the usual input. But, if you&#8217;re just grabbing a character from the regular input, using <code>getchar()<\/code> is like taking a quick and easy route \u2013 it&#8217;s the same as saying <code>getc(stdin)<\/code>. So, if you&#8217;re sticking to the standard input, <code>getchar()<\/code> is the simpler choice.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1700220342321\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q3. What is the difference between fgetc and getc?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans.<br \/>In C, there are two buddies, <code>fgetc()<\/code> and <code>getc()<\/code>, doing the same job of getting characters. But here&#8217;s the thing: <code>fgetc()<\/code> is a real subroutine, not just a fancy term like &#8220;macro&#8221; used for <code>getc()<\/code>. However, there&#8217;s a trade-off \u2013 <code>fgetc()<\/code> might be a bit slower than <code>getc()<\/code>, but it&#8217;s more efficient in terms of using less disk space. So, depending on your needs, you might choose one over the other.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>What Is The Return Type Of Getchar(), Fgetc() And Getc() ? In C, when you use getchar(), fgetc(), or getc(), what you get back is not a character but an integer. So, it&#8217;s a good idea to catch that integer by using an integer-type variable. These functions return the ASCII value of the character you &#8230; <a title=\"What Is The Return Type Of Getchar(), Fgetc() And Getc() ?\" class=\"read-more\" href=\"https:\/\/www.skillvertex.com\/blog\/what-is-the-return-type-of-getchar-fgetc-and-getc\/\" aria-label=\"More on What Is The Return Type Of Getchar(), Fgetc() And Getc() ?\">Read more<\/a><\/p>\n","protected":false},"author":4,"featured_media":3599,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[589,588],"class_list":["post-3597","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-fgetc-and-getc","tag-what-is-the-return-type-of-getchar","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"_links":{"self":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/3597","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/comments?post=3597"}],"version-history":[{"count":6,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/3597\/revisions"}],"predecessor-version":[{"id":7948,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/3597\/revisions\/7948"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media\/3599"}],"wp:attachment":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media?parent=3597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/categories?post=3597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/tags?post=3597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}