#include <stdio.h>                                                              
#include <stdlib.h>                                                             
#include <string.h>                                                             
#define SIZE 50                                                                 
                                                                                
struct employee                                                                 
{                                                                               
    char *empname;                                                              
    char *empid;                                                                
    int age;                                                                    
    char *addr;                                                                 
};                                                                              
                                                                                
int main()                                                                      
{                                                                               
    FILE *fp = NULL;                                                            
    int i = 0;                                                                  
    struct employee var = {NULL, NULL, 0, NULL};                                
    char line[SIZE] = {0}, *ptr = NULL;                                         
   
    /* uncommented in your code - Here reading from stdin instead 
   
    // Open file for Reading 
    if (NULL == (fp = fopen("file.txt","r")))                                   
    {                                                                           
        perror("Error while opening the file.\n");                              
        exit(EXIT_FAILURE);                                                     
    }                                                                           
   */

    /* Allocate Memory */                                                       
    var.empname = malloc(SIZE);                                                 
    var.empid = malloc(SIZE);                                                   
    var.addr = malloc(SIZE);          
    
    /* Uncomment Below line - Here Reading from stdin 
    while (EOF != fscanf(fp, "%s", line))                                       
    */
    
    while (EOF != fscanf(stdin, "%s", line))                                       
    {                                                                           
        /* 1. Read each line from the file */                                   
        printf("\n\n Read line:  %s\n", line);                       
                                                                                
        /* 2. Tokenise the read line, using "\" delimiter*/                     
        ptr = strtok(line, "\\");                                               
        printf("ptr at :%s\n", ptr);                                     
        var.empname = ptr;                                                      
                                                                                
        while (NULL != (ptr = strtok(NULL, "\\")))                              
        {                                                                       
            i++;                                                                
            printf("=====%d==== ptr: %s\n", i, ptr);                             
                                                                                
            /* 3. Store the tokens as per structure members , where (i==0) is first member and so on.. */
            if(i == 1)                                                          
                var.empid = ptr;                                                
            else if(i == 2)                                                     
                var.age = atoi(ptr);                                            
            else if (i == 3)                                                    
                var.addr = ptr;                                                 
        }                                                                       
        i = 0;                                                                  
        printf("After Reading: EmpName:[%s] EmpId:[%s] Age:[%d] Addr:[%s]\n", var.empname, var.empid, var.age, var.addr);                                     
    }                                                                           
                                                                                
    //fclose(fp);                                                                 
    return 0;                                                                   
}                                                                                           
                                 
                                      