expected declaration or statement at end of input
hello. please, i need help. my source code is:
#include "stdio.h"
#include "malloc.h"
#include "string.h"
#define MAX_LENGTH 30
#define COUNT_ITEM 20
struct PARAM
{
char *pchMeno;
char *pchPriezvisko;
char *pchRok;
char *pchKlub;
char *pchDisc;
char *pchKat;
};
struct PARAM *g_Param[COUNT_ITEM];
FILE *g_file;
void Vypis( int nNumRec )
{
int i;
for( i = 0; i < nNumRec; i++ )
{
printf( "[%d] %s %s %s %s %s %s\n", i,
g_Param[i]->pchMeno,
g_Param[i]->pchPriezvisko,
g_Param[i]->pchRok,
g_Param[i]->pchKlub,
g_Param[i]->pchDisc,
g_Param[i]->pchKat);
}
}
void FreeMem( int nDelRec )
{
free( g_Param[nDelRec]->pchMeno );
free( g_Param[nDelRec]->pchPriezvisko );
free( g_Param[nDelRec]->pchRok );
free( g_Param[nDelRec]->pchKlub );
free( g_Param[nDelRec]->pchDisc );
free( g_Param[nDelRec]->pchKat );
free( g_Param[nDelRec]);
}
void Pridaj( int *pnNumRec )
{
if( *pnNumRec < COUNT_ITEM )
{
g_Param[*pnNumRec] = (struct PARAM *) malloc(sizeof(struct PARAM));
g_Param[*pnNumRec]->pchMeno = (char*) malloc(MAX_LENGTH);
printf( "Meno : ");
scanf( "%s", g_Param[*pnNumRec]->pchMeno );
g_Param[*pnNumRec]->pchPriezvisko = (char*) malloc(MAX_LENGTH);
printf( "Priezvisko : ");
scanf( "%s", g_Param[*pnNumRec]->pchPriezvisko );
g_Param[*pnNumRec]->pchRok = (char*) malloc(MAX_LENGTH);
printf( "Rok narodenia : ");
scanf( "%s", g_Param[*pnNumRec]->pchRok );
g_Param[*pnNumRec]->pchKlub = (char*) malloc(MAX_LENGTH);
printf( "Klub : ");
scanf( "%s", g_Param[*pnNumRec]->pchKlub );
g_Param[*pnNumRec]->pchDisc = (char*) malloc(MAX_LENGTH);
printf( "Disciplina : ");
scanf( "%s", g_Param[*pnNumRec]->pchDisc );
g_Param[*pnNumRec]->pchKat = (char*) malloc(MAX_LENGTH);
printf( "Kategoria : ");
scanf( "%s", g_Param[*pnNumRec]->pchKat );
(*pnNumRec)++;
}
else
{
printf( "Zoznam je plny" );
}
}
void Zmaz(int *pnNumRec)
{
int i;
int nRecDel;
Vypis( *pnNumRec );
if( *pnNumRec != 0 )
{
printf( "Zadaj cislo zaznamu ktory chces zmazat : " );
scanf( "%d", &nRecDel );
for( i = nRecDel; i < ((*pnNumRec)-1); i++ )
{
strcpy( g_Param[i]->pchMeno,g_Param[i+1]->pchMeno);
strcpy( g_Param[i]->pchPriezvisko,g_Param[i+1]->pchPriezvisko);
strcpy( g_Param[i]->pchRok,g_Param[i+1]->pchRok);
strcpy( g_Param[i]->pchKlub,g_Param[i+1]->pchKlub);
strcpy( g_Param[i]->pchDisc,g_Param[i+1]->pchDisc);
strcpy( g_Param[i]->pchKat,g_Param[i+1]->pchKat);
}
if ((*pnNumRec)-1==0)
{
FreeMem( 0 );
}
else
{
FreeMem( (*pnNumRec)-1 );
}
(*pnNumRec)--;
}
else
{
printf( "!!! Prazdny zoznam !!!\n" );
}
}
void Zotried(int nNumRec)
{
int i;
int j;
struct PARAM *helpParam;
for( i = 0; i < nNumRec-1; i++)
{
for( j = i+1; j < nNumRec; j++ )
{
if( strcmp( g_Param[j]->pchDisc, g_Param[i]->pchDisc ) < 0 )
{
helpParam = g_Param[j];
g_Param[j] = g_Param[i];
g_Param[i] = helpParam;
}
}
}
}
void Nacitaj( int *pnNumRec )
{
int nRet;
int i;
for( i = 0; i < *pnNumRec; i++ )
{
FreeMem( i );
}
*pnNumRec = 0;
g_file = fopen( "zoznam.dat", "r" );
do
{
if( *pnNumRec < COUNT_ITEM )
{
g_Param[*pnNumRec] = (struct PARAM *) malloc(sizeof(struct PARAM));
g_Param[*pnNumRec]->pchMeno = (char*) malloc(MAX_LENGTH);
g_Param[*pnNumRec]->pchPriezvisko = (char*) malloc(MAX_LENGTH);
g_Param[*pnNumRec]->pchRok = (char*) malloc(MAX_LENGTH);
g_Param[*pnNumRec]->pchKlub = (char*) malloc(MAX_LENGTH);
g_Param[*pnNumRec]->pchDisc = (char*) malloc(MAX_LENGTH);
g_Param[*pnNumRec]->pchKat = (char*) malloc(MAX_LENGTH);
nRet = fscanf( g_file, "%s\t%s\t%s\t%s\t%s\t%s\n",
g_Param[*pnNumRec]->pchMeno,
g_Param[*pnNumRec]->pchPriezvisko,
g_Param[*pnNumRec]->pchRok,
g_Param[*pnNumRec]->pchKlub,
g_Param[*pnNumRec]->pchDisc,
g_Param[*pnNumRec]->pchKat);
if( nRet != EOF )
{
(*pnNumRec)++;
}
else
{
FreeMem( *pnNumRec );
// (*pnNumRec)--;
}
}
else
{
printf( "Zoznam je plny" );
break;
}
}while( nRet != EOF );
fclose( g_file );
}
void Uloz( int nNumRec )
{
int i;
g_file = fopen( "zoznam.dat", "w" );
if( g_file == NULL )
{
printf("nemozem zapisat");
}
else
{
for( i = 0; i < nNumRec; i++ )
{
fprintf( g_file, "%s\t%s\t%s\t%s\t%s\t%s\n",
g_Param[i]->pchMeno,
g_Param[i]->pchPriezvisko,
g_Param[i]->pchRok,
g_Param[i]->pchKlub,
g_Param[i]->pchDisc,
g_Param[i]->pchKat);
}
fclose( g_file );
}
}
void main(int argc, char *argv[])
{
char chChoice;
int nNumRec;
int i;
nNumRec = 0;
do
{
printf( "\n**************** MENU ****************\n" );
printf( "[1] Pridaj zaznam\n[2] Zmaz zaznam\n[3] Zotried zoznam\n[4] Vypis zoznam\n" );
printf( "[5] Uloz do suboru\n[6] Nacitaj zo suboru\n[9] Ukonci program\n" );
printf( "\nZadaj volbu : " );
scanf( "%s", &chChoice );
printf( "\n" );
switch( chChoice )
{
case '1': Pridaj( &nNumRec );
break;
case '2': Zmaz( &nNumRec );
break;
case '3': Zotried( nNumRec);
break;
case '4': Vypis( nNumRec );
break;
case '5': Uloz( nNumRec );
break;
case '6': Nacitaj( &nNumRec );
break;
}
}while( chChoice != '9' );
for( i = 0; i < nNumRec; i++ )
{
FreeMem( i );
}
}
problem is that if i try to compile it in putty through VIM EDITOR (example: cc -o example.exe example.c), it displays an error EXPECTED DECLARATION OR STATEMENT AT END OF INPUT on the last line(i think it is 227th line). it is error with function NACITAJ... do you know where the problem is. i am beginner at programming so i cant find an error. PLEASE HELP ME
|