C Programming Tutorial - puts and gets



Puts and gets are awesome way to putting strings to the screen and getting string from the screen.
scanf

in Scanf Thileban Nagarasa it breaks after space

it allows the user enter the cats name and cats food and prints it on the screen.

#include<stdio.h>

int main() {
  char catsName[50];
  char catsFood[25];
  char sentence[75] = "";
  
  puts ("Whats the cats dumb name? "); (it acts like printf and automatically adds a newline, you will see the cursor in the next line)
  gets (catsName); (this acts like scanf)
  
  puts ("Whats does he eat? ");
  gets (catsFood);
  

  strcat(sentence, catsName); (tags one string at the end of the other)
  strcat(sentence, " loves to eat ");
  strcat (sentence, catsFood); 
  
  puts(sentence); (what we want to print?)
  
  return 0;
}

Output

Pussy McStanky loves to eat fish  

Comments