I think this code will solve your problems,
I did some of the modification in the program.
Code:
#include <stdio.h>
#include <string.h>
#include<malloc.h>

int main(){
char *data = (char *)malloc(10);
char *tmp;
char temp[4];
char message[]="Correct Password";
data=getpass("\nGive me data:");
int len=strlen(data);
if (strcmp(data,"Virtual")==0){
    printf("%s",message);
}else{
    strncpy(temp,data,4);
    temp[4]='\0';
    printf("Your password is wrong\n Data:%s length:%d\n",temp,len);
}

return 0;
}
Fatima Khan like this