Q:

Why gets(sen) is not working in this code?

#include <stdio.h>
#include <string.h>

int main() {
  char a;
  char s[100];
  char sen[100];

  scanf("%c",&a); // take character
  printf("%c",a); //print character
  scanf("%s",s); //take input as a word
  printf("\n%s",s); //print the word

  if((gets(sen))=='\n')
    gets(sen);// take input as a string

  puts(sen); //print that string
}

As gets() takes input from buffer so it will take '\n' as input after that another gets() command should work but that is not working. It doesn't take any input. Why?

A:

gets(sen) returns sen, which is the address of the char array.
Therefore, what you are trying to do should be
if(strcmp(gets(sen), "\n") == 0)
    gets(sen);// take input as a string

However, this is error-prone because sen can be a space with a newline, which is not "\n" or so.

