{"id":10932,"date":"2022-08-17T05:29:55","date_gmt":"2022-08-17T05:29:55","guid":{"rendered":"http:\/\/fastbitlab.com\/?p=10932"},"modified":"2023-08-26T09:53:02","modified_gmt":"2023-08-26T04:23:02","slug":"microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\/","title":{"rendered":"Microcontroller Embedded C Programming Lecture 88| &#8216;if&#8217; and &#8216;else&#8217; exercise implementation part-3"},"content":{"rendered":"<div class=\"boldgrid-section\" style=\"background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"container\">\n<div class=\"row\" style=\"padding-top: 35px; padding-bottom: 0px; background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"col-md-1 col-sm-12 col-xs-12 col-lg-1\">\n<div class=\"boldgrid-shortcode\" data-imhwpb-draggable=\"true\">\n\n<\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"col-md-10 col-sm-12 col-xs-12 col-lg-10\">\n<h1 class=\"\" style=\"text-align: center; font-size: 30px; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; line-height: 50px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><strong><span style=\"color: #000080;\">&#8216;if&#8217; and &#8216;else&#8217; exercise implementation part-3<\/span><\/strong><\/h1>\n<div class=\"row bg-editor-hr-wrap\" style=\"border-width: 0px; margin-top: -25px;\">\n<div class=\"col-lg-12 col-md-12 col-xs-12 col-sm-12\">\n<div>\n<p>&nbsp;<\/p>\n<div class=\"bg-hr bg-hr-10 color2-color\" style=\"border-style: solid; border-width: 0px 0px 3px;\"><\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<h3 class=\"\" style=\"font-size: 25px; line-height: 40px; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><strong><span style=\"text-decoration: underline; color: #333399;\">&#8216;if&#8217; and &#8216;else&#8217; exercise<\/span><\/strong><\/h3>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In the <\/span><strong><span style=\"color: #ff6600;\"><a style=\"color: #ff6600; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/microcontroller-embedded-c-programming-if-else-exercise\/\" target=\"_blank\" rel=\"noopener\">previous article<\/a><\/span><\/strong><span style=\"font-weight: 400;\">,<span style=\"color: #000000;\"> we broke our application by entering a character. Let&#8217;s try to solve this issue in this article.<\/span><\/span><\/p>\n<figure id=\"attachment_10935\" aria-describedby=\"caption-attachment-10935\" style=\"width: 548px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-10935 \" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/08\/Figure-1-1024x205.png\" alt=\"Figure 1. Issue\" width=\"548\" height=\"110\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-1024x205.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-300x60.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-768x154.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-600x120.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-120x24.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-500x100.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-200x40.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-400x80.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-800x160.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-1200x240.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1.png 1223w\" sizes=\"(max-width: 548px) 100vw, 548px\" \/><figcaption id=\"caption-attachment-10935\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. Issue<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">To solve this issue, we have to understand the return value of scanf.<\/span><\/p>\n<figure id=\"attachment_10936\" aria-describedby=\"caption-attachment-10936\" style=\"width: 647px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-10936 \" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/08\/Figure-2-1024x498.png\" alt=\"Figure 2. Return value of scanf\" width=\"647\" height=\"315\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2-1024x498.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2-300x146.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2-768x374.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2-600x292.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2-1536x748.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2-120x58.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2-500x243.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2-200x97.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2-400x195.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2-800x389.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2-1200x584.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2.png 1847w\" sizes=\"(max-width: 647px) 100vw, 647px\" \/><figcaption id=\"caption-attachment-10936\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. Return value of scanf<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Here, <\/span><b><span style=\"color: #800080;\">scanf<\/span>(<span style=\"color: #0000ff;\">\u201c%f\u201d<\/span>, &amp;num1);<\/b><span style=\"font-weight: 400;\"> is to read a real number. You should always remember that scanf returns the total number of inputs scanned successfully from the standard input.<\/span><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In the above case, scanf returns 1, if the scan is successful. Why? Because there is the 1 item to be scanned, that is of type %f, that is a real number. So, for this case, a scanf returns 1, if the scan is successful. If the scan is unsuccessful then scanf returns 0.<\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, when you enter a character for the above code, the scanf fails and returns 0 (indicating it has reached the end of the file of the input stream). 0 indicates that the scan is failed. The scan fails for the character input because it was expecting a number. So, you cannot type a character.<\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">When you type a character, the scan fails, and scanf returns immediately with a value of 0. So, based on the return value of the scanf, now we can modify our code. If scanf returns 0, then conclude that the user has entered something else; it&#8217;s invalid input. And based on that, you can take some action. So, let&#8217;s modify the code by checking the return value of the scanf.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now let&#8217;s modify the previous code. First, I would like to check the return value of the scanf. So, here let&#8217;s use one more if statement for the scanf.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><b><span style=\"color: #800080;\">if<\/span>(<span style=\"color: #800080;\">scanf<\/span>(<span style=\"color: #3366ff;\">\u201c%f\u201d<\/span>, &amp;num1) == 0)<\/b><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Because now you are using a scanf as an expression. So, keep scanf inside the parentheses of the if.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">When<\/span><b><span style=\"color: #800080;\"> if<\/span>(<span style=\"color: #800080;\">scanf<\/span>(<span style=\"color: #3366ff;\">&#8220;%f&#8221;<\/span>, &amp;num1))<\/b><span style=\"font-weight: 400;\"> is executed, in this case, this expression returns 1, if the scan is successful. This function call returns 0, if the scan is unsuccessful. So, let&#8217;s compare the return value.<\/span><\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px;\"><span style=\"color: #ff99cc;\">#include<\/span>&lt;stdio.h&gt;\r\n<span style=\"color: #ff99cc;\">#include<\/span>&lt;stdint.h&gt;\r\n\r\n<span style=\"color: #ff99cc;\">int<\/span> main(<span style=\"color: #ff99cc;\">void<\/span>)\r\n{\r\n\r\n<span style=\"color: #ff99cc;\">float<\/span> num1 , num2;\r\n<span style=\"color: #ff00ff;\">printf<\/span>(\"Enter the first number(integer):\");\r\n\r\n<span style=\"color: #ff99cc;\">if<\/span> ( <span style=\"color: #ff00ff;\">scanf<\/span>(\"%f\",&amp;num1) == 0 ){\r\n<span style=\"color: #ff00ff;\">    printf<\/span>(\"invalid input! Exiting ..\\n\");\r\n<span style=\"color: #ff99cc;\">    return<\/span> 0;\r\n}\r\n\r\n<span style=\"color: #ff00ff;\">printf<\/span>(\"Enter the second number(integer):\");\r\n<span style=\"color: #ff99cc;\">if<\/span> ( <span style=\"color: #ff00ff;\">scanf<\/span>(\"%f\",&amp;num2) == 0 ){\r\n<span style=\"color: #ff00ff;\">     printf<\/span>(\"invalid input! Exiting ..\\n\");\r\n<span style=\"color: #ff99cc;\">     return<\/span> 0;\r\n}<\/pre>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">If the scanf statement is equal to 0, that means that the scan has failed. So here we are comparing the return value of the scanf with 0.<\/span><b><span style=\"color: #800080;\"> if<\/span>( <span style=\"color: #800080;\">scanf<\/span>(<span style=\"color: #0000ff;\">\u201c%f\u201d<\/span>, &amp;num1) == 0) <\/b><span style=\"font-weight: 400;\">is true, you can print &#8220;Invalid input Exiting..&#8221; and return from the application here itself. So, return 0.&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, you can even pass some negative numbers to indicate it&#8217;s a failure, but you can use return 0 for this application; it doesn&#8217;t matter. So, let&#8217;s use return 0.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s do the same thing for the second number scanf statement as well. The code is shown above. <\/span><\/p>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here, you are not waiting for the user input, so it returns immediately.<\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">I hope you understand this code and so let&#8217;s do one thing. Let&#8217;s create a small function <\/span><b><span style=\"color: #800080;\">void<\/span> wait_for_user_input(<span style=\"color: #800080;\">void<\/span>)<\/b><span style=\"font-weight: 400;\">. It&#8217;s a void function and let&#8217;s keep the getchar() code in this function.&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Add the prototype of <span style=\"color: #000000;\"><b>wait_for_user_input<\/b><\/span> function at the top. And after that, call this function from wherever you want.<\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Let&#8217;s call the<\/span><b> wait_for_user_input<\/b><span style=\"font-weight: 400;\"> function after the printf statement. Otherwise, the code will be exited immediately, so you&#8217;ll not be able to see the printf statements.&nbsp;<\/span><span style=\"font-weight: 400;\">&nbsp;<\/span><\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px;\"><span style=\"color: #ff99cc;\">#include<\/span>&lt;stdio.h&gt;\r\n<span style=\"color: #ff99cc;\">#include<\/span>&lt;stdint.h&gt;\r\n\r\n<span style=\"color: #ffff00;\">void wait_for_user_input(void);     <span style=\"color: #339966;\">\/\/ <span style=\"font-weight: 400;\">add the prototype<\/span><\/span><\/span>\r\n\r\n<span style=\"color: #ff99cc;\">int<\/span> main(<span style=\"color: #ff99cc;\">void<\/span>)\r\n{\r\n\r\n<span style=\"color: #ff99cc;\">float<\/span> num1 , num2;\r\n<span style=\"color: #ff00ff;\">printf<\/span>(\"Enter the first number(integer):\");\r\n\r\n<span style=\"color: #ff99cc;\">if<\/span> ( <span style=\"color: #ff00ff;\">scanf<\/span>(\"%f\",&amp;num1) == 0 ){\r\n<span style=\"color: #ff00ff;\">     printf<\/span>(\"invalid input! Exiting ..\\n\");\r\n     <span style=\"color: #ffff00;\">wait_for_user_input();<\/span>\r\n<span style=\"color: #ff99cc;\">     return<\/span> 0;\r\n}\r\n\r\n<span style=\"color: #ff00ff;\">printf<\/span>(\"Enter the second number(integer):\");\r\n<span style=\"color: #ff99cc;\">if<\/span> ( <span style=\"color: #ff00ff;\">scanf<\/span>(\"%f\",&amp;num2) == 0 ){\r\n<span style=\"color: #ff00ff;\">     printf<\/span>(\"invalid input! Exiting ..\\n\");\r\n     <span style=\"color: #ffff00;\">wait_for_user_input();<\/span>\r\n<span style=\"color: #ff99cc;\">     return<\/span> 0;\r\n}\r\n\r\n<span style=\"color: #339966;\">int32_t<\/span> n1, n2;\r\n\r\n<span style=\"color: #339966;\">\/* we are storing only integer part of the real numbers*\/<\/span>\r\nn1 = num1;\r\nn2 = num2;\r\n\r\n<span style=\"color: #ff99cc;\">if<\/span>( (n1 != num1) || (n2 != num2) ){\r\n<span style=\"color: #ff00ff;\">printf<\/span>(\"Warning ! comparing only integer part\\n\");\r\n}\r\n\r\n<span style=\"color: #ff99cc;\">if<\/span>(n1 == n2){\r\n<span style=\"color: #ff00ff;\">    printf<\/span>(\"Numbers are equal\\n\");\r\n}<span style=\"color: #ff99cc;\">else<\/span>{\r\n\r\n<span style=\"color: #ff99cc;\">if<\/span>(n1 &lt; n2){\r\n<span style=\"color: #ff00ff;\">    printf<\/span>(\"%d is bigger\\n\",n2);\r\n}<span style=\"color: #ff99cc;\">else<\/span>{\r\n<span style=\"color: #ff00ff;\">    printf<\/span>(\"%d is bigger\\n\",n1);\r\n}\r\n}\r\n\r\n<span style=\"color: #ffff00;\">wait_for_user_input();<\/span>\r\n\r\n}\r\n\r\n\r\n<span style=\"color: #ffff00;\">void wait_for_user_input(void)<\/span>\r\n{\r\n\r\n<span style=\"color: #ff00ff;\">printf<\/span>(\"Press enter key to exit this application\");\r\n\r\n<span style=\"color: #ff99cc;\">while<\/span>(getchar() != '\\n')\r\n{\r\n<span style=\"color: #008000;\">     \/\/just read the input buffer and do nothing<\/span>\r\n}\r\ngetchar();\r\n\r\n}<\/pre>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">I hope you understand this code. We are just checking the return value of the scanf and comparing that with 0.<\/span><\/p>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now let&#8217;s compile the code and check the output.<\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">First, let&#8217;s try with our numbers and see whether it is working properly or not. This is working fine, as shown in Figure 3.<\/span><\/p>\n<figure id=\"attachment_10941\" aria-describedby=\"caption-attachment-10941\" style=\"width: 667px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-10941 \" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/08\/Figure-7-1024x248.png\" alt=\"if and else exercise implementation\" width=\"667\" height=\"161\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-7-1024x248.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-7-300x73.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-7-768x186.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-7-600x145.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-7-120x29.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-7-500x121.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-7-200x48.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-7-400x97.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-7-800x194.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-7-1200x291.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-7.png 1225w\" sizes=\"(max-width: 667px) 100vw, 667px\" \/><figcaption id=\"caption-attachment-10941\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3. Output<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s try with a character. I input a character B. Here we can see that it is now handling it properly. It says &#8220;Invalid input! Exiting..&#8221;, and the application does not allow you to enter more inputs. It is just exiting.<\/span><\/p>\n<figure id=\"attachment_10942\" aria-describedby=\"caption-attachment-10942\" style=\"width: 635px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-10942 \" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/08\/Figure-8.png\" alt=\"if and else exercise implementation\" width=\"635\" height=\"173\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-8.png 920w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-8-300x82.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-8-768x209.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-8-600x163.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-8-120x33.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-8-500x136.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-8-200x54.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-8-400x109.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-8-800x217.png 800w\" sizes=\"(max-width: 635px) 100vw, 635px\" \/><figcaption id=\"caption-attachment-10942\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 4. Output<\/span><\/figcaption><\/figure>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In the following article, let&#8217;s understand the <span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"https:\/\/fastbitlab.com\/microcontroller-embedded-c-programming-lecture-89-if-else-if-ladder-statements\/\">if-else-if ladder<\/a><\/span>.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 20px; line-height: 40px; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><b>FastBit Embedded Brain Academy Courses<\/b><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; border-width: 0px;\"><span style=\"color: #000000;\">C<span style=\"font-weight: 400;\"><span style=\"color: #000000;\">lick here:<\/span>&nbsp;<\/span><\/span><span style=\"color: #0000ff;\"><a style=\"color: #0000ff; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/course1\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/fastbitlab.com\/course1<\/span><\/a><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &#8216;if&#8217; and &#8216;else&#8217; exercise implementation part-3 &nbsp; &nbsp; &#8216;if&#8217; and &#8216;else&#8217; exercise In the previous article, we broke our application by entering a character. Let&#8217;s try to solve this issue in this article. &nbsp; To solve this issue, we have to understand the return value of scanf. &nbsp; Here, scanf(\u201c%f\u201d, &amp;num1); is to read [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":10936,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[8],"tags":[16],"class_list":["post-10932","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-microcontroller-embedded-c-programming","entry","has-media"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>&#039;if&#039; and &#039;else&#039; Exercise Implementation Part 3 - Handling Invalid Input<\/title>\n<meta name=\"description\" content=\"Exercise: Learn how to handle invalid input using &#039;if&#039; and &#039;else&#039; statements in C programming. Understand utilize the return value of scanf\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"&#039;if&#039; and &#039;else&#039; Exercise Implementation Part 3 - Handling Invalid Input\" \/>\n<meta property=\"og:description\" content=\"Exercise: Learn how to handle invalid input using &#039;if&#039; and &#039;else&#039; statements in C programming. Understand utilize the return value of scanf\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\/\" \/>\n<meta property=\"og:site_name\" content=\"FastBit EBA\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/fastbiteba\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-17T05:29:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-26T04:23:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1847\" \/>\n\t<meta property=\"og:image:height\" content=\"899\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"FastBitLab\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:site\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"FastBitLab\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"Microcontroller Embedded C Programming Lecture 88| &#8216;if&#8217; and &#8216;else&#8217; exercise implementation part-3\",\"datePublished\":\"2022-08-17T05:29:55+00:00\",\"dateModified\":\"2023-08-26T04:23:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\\\/\"},\"wordCount\":734,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/Figure-2.png\",\"keywords\":[\"Microcontroller Embedded C programming Lectures\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\\\/\",\"name\":\"'if' and 'else' Exercise Implementation Part 3 - Handling Invalid Input\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/Figure-2.png\",\"datePublished\":\"2022-08-17T05:29:55+00:00\",\"dateModified\":\"2023-08-26T04:23:02+00:00\",\"description\":\"Exercise: Learn how to handle invalid input using 'if' and 'else' statements in C programming. Understand utilize the return value of scanf\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/Figure-2.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/Figure-2.png\",\"width\":1847,\"height\":899,\"caption\":\"Figure 2. Return value of scanf\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Microcontroller Embedded C Programming Lecture 88| &#8216;if&#8217; and &#8216;else&#8217; exercise implementation part-3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"name\":\"FastBit EBA\",\"description\":\"Your Online Academy of Embedded Systems\",\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\",\"name\":\"FastBit EBA\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"width\":640,\"height\":640,\"caption\":\"FastBit EBA\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/fastbiteba\\\/\",\"https:\\\/\\\/x.com\\\/fastbiteba\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/fastbit-embedded-brain-academy-b3167b124\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCa1REBV9hyrzGp2mjJCagBg\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\",\"name\":\"FastBitLab\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"caption\":\"FastBitLab\"},\"description\":\"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"'if' and 'else' Exercise Implementation Part 3 - Handling Invalid Input","description":"Exercise: Learn how to handle invalid input using 'if' and 'else' statements in C programming. Understand utilize the return value of scanf","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:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\/","og_locale":"en_US","og_type":"article","og_title":"'if' and 'else' Exercise Implementation Part 3 - Handling Invalid Input","og_description":"Exercise: Learn how to handle invalid input using 'if' and 'else' statements in C programming. Understand utilize the return value of scanf","og_url":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2022-08-17T05:29:55+00:00","article_modified_time":"2023-08-26T04:23:02+00:00","og_image":[{"width":1847,"height":899,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2.png","type":"image\/png"}],"author":"FastBitLab","twitter_card":"summary_large_image","twitter_creator":"@fastbiteba","twitter_site":"@fastbiteba","twitter_misc":{"Written by":"FastBitLab","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"Microcontroller Embedded C Programming Lecture 88| &#8216;if&#8217; and &#8216;else&#8217; exercise implementation part-3","datePublished":"2022-08-17T05:29:55+00:00","dateModified":"2023-08-26T04:23:02+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\/"},"wordCount":734,"commentCount":0,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2.png","keywords":["Microcontroller Embedded C programming Lectures"],"articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\/","url":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\/","name":"'if' and 'else' Exercise Implementation Part 3 - Handling Invalid Input","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2.png","datePublished":"2022-08-17T05:29:55+00:00","dateModified":"2023-08-26T04:23:02+00:00","description":"Exercise: Learn how to handle invalid input using 'if' and 'else' statements in C programming. Understand utilize the return value of scanf","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2.png","width":1847,"height":899,"caption":"Figure 2. Return value of scanf"},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-88-if-and-else-exercise-implementation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Microcontroller Embedded C Programming Lecture 88| &#8216;if&#8217; and &#8216;else&#8217; exercise implementation part-3"}]},{"@type":"WebSite","@id":"https:\/\/fastbitlab.com\/blog\/#website","url":"https:\/\/fastbitlab.com\/blog\/","name":"FastBit EBA","description":"Your Online Academy of Embedded Systems","publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fastbitlab.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fastbitlab.com\/blog\/#organization","name":"FastBit EBA","url":"https:\/\/fastbitlab.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","width":640,"height":640,"caption":"FastBit EBA"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/fastbiteba\/","https:\/\/x.com\/fastbiteba","https:\/\/www.linkedin.com\/in\/fastbit-embedded-brain-academy-b3167b124\/","https:\/\/www.youtube.com\/channel\/UCa1REBV9hyrzGp2mjJCagBg"]},{"@type":"Person","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d","name":"FastBitLab","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","caption":"FastBitLab"},"description":"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries."}]}},"_links":{"self":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/10932","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/comments?post=10932"}],"version-history":[{"count":5,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/10932\/revisions"}],"predecessor-version":[{"id":15244,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/10932\/revisions\/15244"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/10936"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=10932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=10932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=10932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}