Products
Services
Contact Us

Scripts: C :: Data processing :: Library Article #2

Developer's Section

Processing Data from standard input
By: Erobo Team Member

Hire a Developer for Related Work / Installation | $55 hr
Rating:  | Rate It:   
Average Votes: (1959)
Favorites:

The following program demonstrates how to process data from standard input.

In this example we will be using scanf and fgets to process data coming from standard input:

 Code Snippet 1

#include <time.h>                                                      
#include <decimal.h>                                                   
#include <stdio.h>                                                     
#include <stdlib.h>  


#define AREA_1_EMP               1
#define AREA_2_EMP               2
#define aREA_3_EMP                3
#define Manager_1_EMP            4
#define Manager_2_EMP            5
#define Manager_3_EMP            11
#define General_Manager            12
#define BOSS_2                          13


typedef  unsigned char text;
typedef   signed int sint; 

/* Using C processing standard input */

/*Prompt the user to enter information in C */

main()
{

    sint sal, empno, deptno, emp_sal;

    text *empName, *jobDescription, *depName, *strRes;

    time_t  currtime;                                                    
    decimal(9,0) theTime;                                                
    char charTime[10] = {0};                                             
                                                                       
    time(&currtime);  
                                                   
    strftime(charTime,sizeof(charTime)-1,"%Y%m%d",localtime(&currtime)); 

    theTime = atoi(charTime);                                            
                                                                       
    printf("New Employee (Data Entry) - date: theTime = %D(9,0) \n", theTime);

    /* Prompt for employee name. */
    printf("\nEnter employee name (or CR to EXIT): ");

    fgets((char *) empName, sizeof empName, stdin);

    strRes = (text *) strchr((char *) empName, '\n');

    /*  Prompt for the employee's salary. */
    printf("Enter new employee salary: ");
    
    scanf("%d", &sal);

    emp_sal = (sal <= 0) ? 0 : sal; /* set salary variable */

    printf("Enter employee Number: ");
            scanf("%d", &empno);
   
    printf("Enter department Number: ");
            scanf("%d", &deptno);
    
    printf("\n\n%s added to the department Number %d  as employee 
                number %d\n", empName, deptno, empno);

     /*  additional information may be used. */

}


See other Scripts in Data processing

Submit Your Scripts:


System Message:
  • Your C script has been sent. Please allow 48 hours for processing.


If you would like to have your C scripts published in this section please fill out
the form below:
*Your Name or Username:
Home Town:
*Email:
*Description and Code:
*Enter Code shown
to the right:

[ Refresh Image ]