title: What is the difference between getchar/putchar, gets/puts and fgets/fputs (in C)?
body: <p>I am currently studying input and output in C and I have found out that there are about a billion different ways to get input, such as, getch, getchar, gets and fgets, and the same with output (putchar, puts, fputs, etc.).</p>
  
  <p>All these different methods of I/O are confusing me quite a bit, so I came on here to ask what the basic differences between the aforementioned functions are.</p>
  
  <p>I also wrote a bit of code using these different functions and I commented in how I think they work, based on what I've learnt, but I'm not sure if my understanding is correct. I've read up on them in other places as well, but the explanations are very complicated and don't seem coherent.</p>
  
  <p>So could anyone please tell me if I am using them correctly and if not, how I should use them and what are the main differences between them?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdbool.h&gt;
  #include &lt;string.h&gt;
  #include &lt;ctype.h&gt;
  
  void individualCharacters()
  {
      char theChar;
  
      while ((theChar = getchar()) != '~') {  //    getchar() stores all characters in a line buffer as it is entered until newline is entered
          putchar(theChar);    // putchar() prints the characters in the line buffer and does not print a newline, line buffering depends on compiler
      }
  }
  
  void withoutF()
  {
      char name[50];
  
      printf("What is your name? ");
  
      gets(name);    // receives a string until newline is entered, newline is then replaced with string terminator, array limit should not be passed
  
      puts("Hi");    // only prints one string at a time and adds the newline because gets() previously replaces the newline
      puts(name);
  }
  
  void withF()
  {
      char name[50];
  
      printf("What is your name? ");
  
      fgets(name, 50, stdin);    // does add a newline so the newline takes up one space in the array, it stores input until either newline is entered or array limit is reached
  
      fputs("Hi ", stdout);    // does not print a newline but prints the string input up to the array limit
      fputs(name, stdout);
  }
  
  void main()
  {
      //sum();
  
      //individualCharacters();
  
      //withoutF();
  
      //withF();
  
      //printRandomString();
  }
  </code></pre>
  
  <p>These are just some functions I wrote that get input and display output in different ways, but I'm having trouble understanding why there are so many different ways of doing so.</p>
  
  <p>If I have made any mistakes using the I/O functions, feel free to tell me so I can make amendments.</p>
  
  <p>Thank you</p>