Hi! This board has helped me tremendously on previous projects. However, I am kind of at a loss as to why I keep getting the compile error when my insertion sort isn't commented out:
error: subscripted value is neither array nor pointer nor vector.
I am using gcc compiler and am running this on Linux. I am not very familiar with programming, so please don't be to harsh on me, although any help is GREATLY appreciated!
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX = 30;
struct employees{
char surname[30];
char firstName[30];
char deptName[30];
char payRate[30];
char eyeColor[30];
};
int main(){
char surname[30];
char firstName[30];
char deptName[30];
char payRate[30];
char eyeColor[30];
int i = 0;
FILE *inputFile;
FILE *outputFile;
char inputFileName[20];
char outputFileName[20];
int numRecs;
printf("Enter the name of the file you wish to read employee data from: \n");
scanf(" %s" ,inputFileName);
inputFile = fopen(inputFileName, "r");
printf("What is the name of the output file you wish to output your report to? \n");
scanf(" %s" ,outputFileName);
outputFile = fopen(outputFileName, "w");
struct employees structure;
struct employees *empData;
//employees data[30];
fprintf(outputFile, "%-15s", "Surname");
fprintf(outputFile, "%-15s", "First Name");
fprintf(outputFile, "%-19s", "Dept");
fprintf(outputFile, "%-15s", "Pay Rate");
fprintf(outputFile, "%-15s", "Eye Color");
while((fscanf(inputFile, "%s", surname)) != EOF){
fscanf(inputFile, "%s %s %s %s", firstName, deptName, payRate, eyeColor);
strcpy(structure.surname, surname); //all of these are getting stored in the struct.
strcpy(structure.firstName, firstName);
strcpy(structure.deptName, deptName);
strcpy(structure.payRate, payRate);
strcpy(structure.eyeColor, eyeColor);
empData = &structure;
//insertion sort**************************************************************************************************************************
/*int i;
int x;
int n;
for (i=0; i < n; i++)
{
int j, v = structure[i].deptName;
x = structure[i];
for (j = i - 1; j >= 0; j--)
{
if (structure[j].deptName >= v) break;
structure[j + 1] = structure[j];
}
structure[j + 1].a = v;
structure[j + 1] = x;
}*/
fprintf(outputFile, "\n%-15s %-15s %-19s %-15s %-15s", empData -> surname, empData -> firstName, empData -> deptName, empData -> payRate, empData -> eyeColor);
}
numRecs++;
}