Im down to a deadline and need to solve the problems with this code. When compiling its giving me the errors:
[12:22:05][peg002@lnxAcadShell01][/home/peg002/LAB4]+ make
cc -c -o lib/SelectionSort.o lib/SelectionSort.c
lib/SelectionSort.c:6: error: array type has incomplete element type
lib/SelectionSort.c:6: warning: âstruct employeeâ declared inside parameter list
lib/SelectionSort.c:6: warning: its scope is only this definition or declaration, which is probably not what you want
lib/SelectionSort.c: In function âSelectionSortâ:
lib/SelectionSort.c:9: error: array type has incomplete element type
make: *** [lib/SelectionSort.o] Error 1
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MaxSize 30
void SelectionSort(struct employee eTable[MaxSize], int numEntries, FILE *outFile){
struct employee temp[1];
int maxPt;
int j, k;
for(j = (numEntries -1); j > 0; j--){
maxPt = 0;
for(k = 1; k <= j; k++)
if(strcmp(eTable[k].dept, eTable[maxPt].dept) > 0)
maxPt = k;
temp = eTable[maxPt];
eTable[maxPt] = eTable[j];
eTable[j] = temp;
}
fprintf(outFile, "\n\n********************SORTED DATA FROM ''D'' OPTION SORT**************************\n\n\n");
for(k=0; k < numEntries; k++){
fprintf(outFile, "%-10s\t%-12s\t%-20s\t%-4.2f\t%-10s\n", eTable[k].surname, eTable[k].given, eTable[k].dept, eTable[k].payRate, eTable[k].eyeColor);
}
}
I'm clueless as to how to fix this. I don't know if its necessary to be able to help, but here is my main program..
Code:
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#define MaxSize 30
//Define struct//
struct employee {
char surname[10];
char given[12];
char dept[20];
float payRate;
char eyeColor[8];
};
void (*SelectionSort_d)();
void (*SelectionSort2_d)();
void (*SelectionSort3_d)();
void (*TemplateSelectionSort_d)();
int main(){
FILE *inFile;
FILE *outFile;
char resp = 'Y';
char fileInName[20];
char fileOutName[20];
int k;
int numRecords = 0;
//Prompting user for Input file//
while(resp == 'Y' || resp == 'y'){
printf("Please enter the file you'd like to read from: ");
scanf("%s", fileInName);
if((fopen(fileInName, "r")) == NULL){
printf("Could not open requested file. Would you like to enter another file? [Y/N]: ");
scanf("%*c %c", &resp);
}
else {
inFile = fopen(fileInName, "r");
break;
}
if(resp == 'n' || resp == 'N')
exit(1);
}
//Prompting user for Output File//
printf("Please enter the file you'd like to write to: ");
scanf("%s", fileOutName);
if(fopen(fileOutName, "r") != NULL){
printf("The file you are attempting to write to already exists! Overwrite?? [Y/N]: ");
scanf("%*c %c", &resp);
if(resp == 'Y' || resp == 'y')
outFile = fopen(fileOutName, "w");
else {
printf("Aborting program to avoid overwriting existing file!!");
exit(1);
}
}
if(fopen(fileOutName, "r") == NULL)
outFile = fopen(fileOutName, "w");
struct employee table[MaxSize];
for(k=0;(fscanf(inFile, "%s%s%s%f%s", table[k].surname, table[k].given, table[k].dept, &table[k].payRate, table[k].eyeColor) != EOF); k++){
numRecords++;
}
for(k=0; k<numRecords; k++){
fprintf(outFile, "%-10s\t%-12s\t%-20s\t%-4.2f\t%-10s\n", table[k].surname, table[k].given, table[k].dept, table[k].payRate, table[k].eyeColor);
}
(*SelectionSort)(table, numRecords, outFile);
(*SelectionSort2)(table, numRecords, outFile);
(*SelectionSort3)(table, numRecords, outFile);
(*TemplateSelectionSort)(table, numRecords, outFile, "surname");
(*TemplateSelectionSort)(table, numRecords, outFile, "dept");
}
Any help would be greatly appreciated!!!!