Problem: A program that will ask an input of an employee data in this format:
ID, firstname_lastname, rate, address, position
Example:
001-111, Juan_DelaCruz, 2, Nasipit Agusan del Norte, Manager
Let Salary rate be equivalent to: 1=250, 2=300, 3=350, 4=375
From the input above, it will display like this:
Employee:001-111
First Name: Juan
Last Name: Dela Cruz
Salary rate: 300
Address: Nasipit Agusan del Norte
Position: Manager
I want the salary rate to automatically display its corresponding equivalent value based on the metric set above. I'm trying to figure out how to manipulate the strings so that whatever the result from string 'rate' will be passed on to string 'sal' with its value. Any inputs will be appreciated!
#include <stdio.h>
#include <string.h>
int main () {
char *empdata[100];
char *id, *fname, *lname, *rate, *add, *posi;
printf("Employee data format: ID, firstname_lastname, rate, address, position");
printf("\nEmployee data example: 001-111, Juan_DelaCruz, 2, Nasipit Agusan del Norte, Manager");
printf("\nLet Salary rate be equivalent to: 1=250, 2=300, 3=350, 4=375");
printf("\n\nEnter your data: ");
gets(empdata[100]);
id=strtok(empdata[100], ",");
fname=strtok(NULL, "_");
lname=strtok(NULL, ",");
rate=strtok(NULL, ",");
add=strtok(NULL, ",");
posi=strtok(NULL, ",");
char sal1[5]="250", sal2[5]="300", sal3[5]="350", sal4[5]="375";
char sal[3];
if (strncmp(rate,"1", 1) == 0) {
strcpy(sal[3],sal1[5]);
} else if (strncmp(rate,"2", 1) == 0) {
strcpy(sal[3],sal2[5]);
} else if (strncmp(rate,"3", 1) == 0) {
strcpy(sal[3],sal3[5]);
} else if (strncmp(rate,"4", 1) == 0) {
strcpy(sal[3],sal4[5]);
}
printf("\n\nHere's your employee data from the input above: ");
printf("\n\nEmployee: %s", id);
printf("\nFirst Name: %s", fname);
printf("\nLast Name: %s", lname);
printf("\nSalary Rate: %s", sal[3]);
printf("\nAddress: %s", add);
printf("\nPosition: %s", posi);
return 0;
}