2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by lionaneesh
-1

This a basic simple program about employee paysheet..Rest is on you ....I provided you the base software... Add some features ... etc etc...

/* Employee Paysheet Program in C */

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

void remove_newline(char *buffer)
{
	int i=strlen(buffer) - 1;
	buffer[i] = '\0';
}	

int main()
{
	FILE *fd;			// This is one way to how to declare file descriptor in C
					// open the file and read the entered data to make some use out of it
	char name[20];
	char salary[15];

	// WE'll open and close the file every time in the loop .. To provide more bacup and security ...Even if the program crashes
	while(1)
	{
		fd = fopen("salary.txt","a");
		memset(&name,'\0',sizeof(name));	// zero out the arrays and make them ready for reuse
		memset(&salary,'\0',sizeof(salary));	
		printf("Enter the Name of employee : ");
		fgets(name,15,stdin);
		remove_newline(name);
		if(strlen(name) < 3)
		{
			printf("Name cannot be less than 3 letters\n");
			continue;
		}
		printf("Enter the salary of the employee : ");		
		fgets(salary,15,stdin);
		remove_newline(salary);
		if(strlen(salary) < 3)
		{
			printf("Salary cannot be a less than 3,2 figured \n");
			continue;
		}		
		fflush(stdin);		// just using it for the sake of name...
		if((strncmp(name,"None",4) == 0) && ( strncmp(salary,"None",4) == 0 )  )
		{
			printf("\n\n\tThanx for Using Employee Paysheet\n\n");			
			break;
		}			
		fprintf(fd,"Employee : %-20s Salary : %15s\n",name,salary);

		fclose(fd);	// Save and exit
	}
	return(0);
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.