Hi the below code is not finished and please excusee the usage of gets() and getch() I will change these in due course. I compiled the below code and saw and error with an array subsript I have never seen before.
invalid use of array with unspecified bounds
I have marked on the program where the error lies.
Code:
#include <stdio.h>
#include <string.h>
#define EMPLOYEE_ARRAY_SIZE 10
#define SALES_ARRAY_SIZE 10
/*function prototype*/
void companyName ( void );
void inputEmployeeNames ( char[] );
void inputSalesFigures ( char[], int, char[][] );
void sortAndDisplayResults(char[], int, char[][], int, float[] );
/*main function - begins program execution -----------------------------------*/
int main ( void )
{
companyName();
getch(); /*freeze console output window*/
return 0; /*return value from int main*/
}
/*function to input company namw*/
void companyName ( void )
{
char nameOfCompany[ 80 ];
printf("Enter company name: ");
gets( nameOfCompany );
inputEmployeeNames ( nameOfCompany );
}
/*function to read in the employee names*/
void inputEmployeeNames ( char nmofcmp[] )
{
int i;
char names[ EMPLOYEE_ARRAY_SIZE ][ 50 ];
printf("\n\nEnter the 10 employee names: ");
for ( i = 0; i < EMPLOYEE_ARRAY_SIZE; i++ )
{
gets( names[ i ]);
}
inputSalesFigures ( nmofcmp, EMPLOYEE_ARRAY_SIZE, names );
}
/*function to read in the sales figures*/
void inputSalesFigures ( char nmofcmp[], int size, char nameArray[][] )
{
int i;
float sales[ SALES_ARRAY_SIZE ];
printf("\n\nEnter 10 sales figures for the month: ");
for ( i = 0; i < SALES_ARRAY_SIZE; i++ )
{
scanf("%f", &sales[ i ]);
}
sortAndDisplayResults ( nmofcmp, EMPLOYEE_ARRAY_SIZE, nameArray, SALES_ARRAY_SIZE, sales);
}
/*function to sort arrays into order and display results
in tabular format*/
void sortAndDisplayResults ( char nmofcmp[], int size, char nameArray[][], int sizeb, float sal[])
{
int i, j;
printf("\n\nCompany Name: %s", nmofcmp);
/*sort names*/
qsort(( char* ) nameArray, size, ( *nameArray ), strcmp );
/*sort values*/
for ( i = 0; i < sizeb -1; i++ )
{
for ( j = 0; j < sizeb -1 -i; j++ )
if ( sal[ j + 1 ] < sal[ j ] )
{
int tmp = sal[ j ];
sal[ j ] = sal[ j + 1 ];
sal[ j + 1 ] = tmp;
}
}
/*display results*/
printf("\n\nSALES MAN\tTOTAL MADE\n\n");
for ( i = 0; i < size; i++ )
{
printf("%s\n", nameArray[ i ]); // ERROR ON THIS LINE
}
printf("\n\n");
for ( i = 0; i < sizeb; i++ )
{
printf("%.2f\n", sal[ i ]);
}
}
As I have said anything else wrong I will fix myself, but that was the only error my C compiler found at this time and im confused by its meaning. Any help apprecioated. I thought it would be best to post all the code as the error may link to somthing I have done previously.