Q:

How to define only 4 characters input by user in C

I want to make program that allow user input only 4 characters. After that, the system should prompt appropriate error message to the users. How look syntax should be?
Here , i am stuck on this,doesnt know how to continue.
#include<stdio.h>
#include<conio.h>
#include <string.h>

int main(int argc,char **argv)
{
    int i;
    char cTransID[4];
    printf("Enter 4 characters of your name: ");
    gets(cTransID);
    printf("Length of string c=%d \n",strlen(cTransID));
}

A:

If it's a case where the user absolutely must enter 4 characters, then you can try utilizing "getch()" along with a for loop.
#include<stdio.h>
#include<conio.h>
#include <string.h>

int main(int argc,char **argv)
{
  int i;
  char cTransID[5];

  printf("Enter 4 characters of your name: ");

  for (i = 0; i <= 3 ;i++)
   {
      cTransID[i] = getch();
      printf("%c",cTransID[i]);
   }

  printf("\n\n%s",cTransID);
  getch();
  return 0;

 }

