i edited my program using the fgets function, and read about it on how to remove the new line character , but since my program deals with and array of structures i'm really confused as to how i go about making a function for this. e,g
Code:
void remove_newline(what should be my arguments)
{
int x=0;
for(x=0; x<what ;x++){
if ( str[i] == '\n' ){
str[i] = '\0';
}
}
}
what should i put to be less that x as it's an array of structures and the size of each structure member is different
here is my code:
Code:
#include <stdio.h>
#include <string.h>
struct employee
{
int employee_ID;
char employee_name[50];
int employee_age;
char employee_DateOfBirth[10];
char employee_address[70];
char employee_TelNo[20];
float emplayee_salary;
}employee_array[50]; // structure variable
void print_line(); // function prototypes
void add_employee();
void edit_employee();
void delete_employee();
void search_employee();
void print_employee();
void remove_newline();
int main()
{
int option;
//clrscr();
print_line();
printf("This program provides the functionality to \n");
printf("interface with an employee information system.");
print_line();
printf("Enter [1] - to enter employee profile \n");
printf("Enter [2] - to edit employee \n");
printf("Enter [3] - to delete employee \n");
printf("Enter [4] - to search for employee \n");
printf("Enter [5] - to print employee information \n");
printf("Enter [0] - to exit\n\n");
printf("Please select an option:\t");
scanf("%d",&option);
getchar();
while(option != 0)
{
switch(option)
{
case 1: add_employee();
break;
case 2: edit_employee();
break;
case 3: delete_employee();
break;
case 4: search_employee();
break;
case 5: print_employee();
break;
default:
printf("\n\nIncorrect Entry!,Please press enter and Try again!\n\n");
getch();
}
printf("\n\n");
print_line();
printf("This program provides the functionality to \n");
printf("interface with an employee information system.");
print_line();
printf("Enter [ 1 ] - to enter employee profile \n");
printf("Enter [ 2 ] - to edit employee \n");
printf("Enter [ 3 ] - to delete employee \n");
printf("Enter [ 4 ] - to search for employee \n");
printf("Enter [ 5 ] - to print employee information \n");
printf("Enter [ 0 ] - to exit\n\n");
printf("Please select an option:\t");
scanf("%d",&option);
}
getch();
}
void print_line()
{
int i;
printf("\n");
for(i=0;i<48;i++)
{
printf("-");
}
printf("\n");
}
void add_employee() // decleration of add employee function
{
int i=0;
int employ_id;
printf("\nEnter employee ID or 0 to exit:\t");
scanf("%d",&employ_id);
while(employ_id!=0){
employee_array[i].employee_ID;
printf("Enter emplayee name:\t");
fflush(stdin);
fgets(employee_array[i].employee_DateOfBirth,sizeof(employee_array[i].employee_DateOfBirth), stdin);
remove_newline();
printf("\nEnter employee age");
scanf(employee_array[i].employee_age);
fflush(stdin);
printf("\nEnter employee Date-Of-Birth:\t");
fgets(employee_array[i].employee_DateOfBirth,sizeof(employee_array[i].employee_DateOfBirth), stdin);
remove_newline();
printf("\nEnter employee address:\t");
fgets(employee_array[i].employee_address,sizeof(employee_array[i].employee_address), stdin);
remove_newline();
printf("\nEnter employee telephone number");
fgets(employee_array[i].employee_TelNo,sizeof(employee_array[i].employee_TelNo), stdin);
remove_newline();
printf("\nEnter employee salary");
scanf("$%f",&employee_array[i].emplayee_salary);
printf("\n\nEnter employee ID or 0 to exit:\t");
scanf("%d",&employee_array[i].employee_ID);
i++;
}
}
void edit_employee()
{
}
void delete_employee()
{
}
void search_employee()
{
}
void print_employee()
{
}
void remove_newline(){
int x=0;
for(x=0; x< ;x++){
if ( str[i] == '\n' ){
str[i] = '\0';
}
}
}