All pastes #979311 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-04-10 07:59 UTC
rendered paste body
void printInfo(struct EmpList *firstEmpPtr)
{
        struct EmpList *currentPtr = NULL;
        currentPtr = firstEmpPtr;
        printf("\n--~~Current Employees~~--\n\n\n");
        printf("Name       ID       Salaries       Class\n\n");

        while(currentPtr != NULL)
        {
                printf("\n\n%s %s %d $%.*lf $%.*lf %s\n\n",
                        currentPtr->lName,
                        currentPtr->fName,
                        currentPtr->id,TWO,
                        currentPtr->salary[ZEROI],TWO,
                        currentPtr->salary[ONE],
                        currentPtr->class);
                currentPtr = currentPtr->nextEmpPtr;
        }
}

void printOne(struct EmpList *empPtr, struct EmpList **firstEmpPtr)
{
        int counter = ZEROI;
        struct EmpList *currentPtr = NULL;
        currentPtr = *firstEmpPtr;
        while(currentPtr != NULL)
        {
                counter++;
                currentPtr = currentPtr->nextEmpPtr;
        }
        printf("\n~~%d Employeed!~~\n", counter);
        printf("\n\nReading %s %s....\n\n", empPtr->fName, empPtr->lName);
}

void print_Menu()
{
        printf("\n%s\n%s\n\n %s\n %s\n %s\n %s\n %s\n",
                        "Kroger's Employee Database",
                        "Main Menu",
                        "'H' Hire",
                        "'I' Initial Salary",
                        "'P' Promotions",
                        "'T' Transfers",
                        "'E' Exit");
}

void hire(FILE **infilePptr, char lineText[], struct EmpList **firstEmpPtr)
{
        struct EmpList *newPtr = NULL;
        struct EmpList *currentPtr = NULL;
        struct EmpList *previousPtr = NULL;
        char tempIDholder[CHAR_BUFF] = {' '};

        newPtr = calloc(ONE, sizeof(struct EmpList));
        if(newPtr != NULL)
        {
                fgets(lineText, CHAR_BUFF, *infilePptr);
                while(lineText[ZEROI] != '*')
                {
                        newPtr = malloc(CHAR_BUFF * sizeof(struct EmpList));
                        currentPtr = NULL;
                        previousPtr = NULL;

                        newPtr->lName = calloc(CHAR_BUFF, sizeof(char));
                        newPtr->fName = calloc(CHAR_BUFF, sizeof(char));
                        newPtr->class = calloc(CHAR_BUFF, sizeof(char));

                        sscanf(lineText, "%s %s %s %s",
                                        newPtr->lName, newPtr->fName,
                                        tempIDholder, newPtr->class);
                        newPtr->id = atoi(tempIDholder);
/*                      printOne(newPtr, firstEmpPtr);*/

                        currentPtr = *firstEmpPtr;
                        previousPtr == NULL;

                        while(currentPtr != NULL)
                        {
                                previousPtr = currentPtr;
                                currentPtr = currentPtr->nextEmpPtr;
                        }
                        if(previousPtr == NULL)
                        {
                                newPtr->nextEmpPtr = *firstEmpPtr;
                                *firstEmpPtr = newPtr;
                        }
                        else
                        {
                                previousPtr->nextEmpPtr = newPtr;
                                newPtr->nextEmpPtr = currentPtr;
                        }
/*              printInfo(*firstEmpPtr);*/
                fgets(lineText,CHAR_BUFF,*infilePptr);
                }
        }
}

void initial(FILE **infilePptr, char lineText[], struct EmpList **firstEmpPtr)
{
        struct EmpList *tempPtr = NULL;
        int tempID = ZEROI;
        double tempSal = ZEROD;
        char stringID[CHAR_BUFF] = {' '};
        char stringSAL[CHAR_BUFF] = {' '};

        fgets(lineText, CHAR_BUFF, *infilePptr);
        while(lineText[ZEROI] != '*')
        {
                tempPtr = calloc(ONE, sizeof(struct EmpList));
                tempPtr = *firstEmpPtr;

                sscanf(lineText, "%s %s", stringID, stringSAL);
                tempID = atoi(stringID);
                tempSal = atof(stringSAL);

                while(tempPtr != NULL)
                {
                        if(tempID == tempPtr->id)
                                tempPtr->salary[ZEROI] = tempSal;

                        tempPtr = tempPtr->nextEmpPtr;
                }
                fgets(lineText, CHAR_BUFF, *infilePptr);
        }
 }

void promote(FILE **infilePptr, char lineText[], struct EmpList **firstEmpPtr)
{
        struct EmpList *tempPtr = NULL;
        int tempID = ZEROI;
        double tempSAL = ZEROD;
        char tempCLASS[CHAR_BUFF] = {' '};
        char stringID[CHAR_BUFF] = {' '};
        char stringSAL[CHAR_BUFF] = {' '};

        fgets(lineText, CHAR_BUFF, *infilePptr);
        while(lineText[ZEROI] != '*')
        {
                tempPtr = calloc(ONE, sizeof(struct EmpList));
                tempPtr = *firstEmpPtr;

                sscanf(lineText, "%s %s %s",stringID, stringSAL, tempCLASS);
                tempID = atoi(stringID);
                tempSAL = atof(stringSAL);
                while (tempPtr != NULL)
                {
                        if (tempID == tempPtr->id)
                        {
                                tempPtr->salary[ONE] = tempSAL;
                                strcpy(tempPtr->class, tempCLASS);
                        }
                        tempPtr = tempPtr->nextEmpPtr;
                }
                fgets(lineText, CHAR_BUFF, *infilePptr);
        }

}

void transfer(FILE **infilePptr, char lineText[], struct EmpList **firstEmpPtr)
{
        struct EmpList *tempPtr = NULL;
        struct EmpList *currentPtr = NULL;
        struct EmpList *previousPtr = NULL;
        int tempID = ZEROI;
        char stringID[CHAR_BUFF] = {' '};

        fgets(lineText, CHAR_BUFF, *infilePptr);
        while (lineText[ZEROI] != '*')
        {
                sscanf(lineText, "%s", stringID);
                tempID = atoi(stringID);

                tempPtr = calloc(ONE, sizeof(struct EmpList));

                if(tempID == (*firstEmpPtr)->id)
                {
                        tempPtr = *firstEmpPtr;
                        *firstEmpPtr = (*firstEmpPtr)->nextEmpPtr;
                        free(tempPtr);
                }
                else
                        currentPtr = *firstEmpPtr;

                while(currentPtr != NULL)
                {
                        previousPtr = currentPtr;
                        currentPtr = currentPtr->nextEmpPtr;
                        if(currentPtr->id == tempID)
                        {
                                previousPtr = currentPtr;
                        }
                }
                fgets(lineText, CHAR_BUFF, *infilePptr);
        }
}

void freeing(struct EmpList *tempPtr)
{
        free(tempPtr->lName);
        free(tempPtr->fName);
        free(tempPtr->class);
        tempPtr->id = ZEROI;
        tempPtr->salary[ZEROI] = ZEROD;
        tempPtr->salary[ONE] = ZEROD;
        free(tempPtr->nextEmpPtr);
        free(tempPtr);
        tempPtr = NULL;
}
[sct2178@omega hwtests]$ vi driver.c