LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-03-2009, 10:21 AM   #1
eMCeee89
LQ Newbie
 
Registered: May 2009
Posts: 1

Rep: Reputation: 0
Exclamation 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
 
Old 05-04-2009, 02:54 AM   #2
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Take a look at the while loop in the main function. It's not working the way your using it.


Code:
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 );
}
}
Should be something like that

Code:
while( chCoice != '9' ){
*/ print the menu */
*/ read input key */
*/ work through case */
}

*/ clear memory */

return 0;
Just a hint. If you post lots of line of codes use the [ CODE][ /CODE] tags. The button left to "php"

Regards Zhjim
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
error: expected declaration or statement at end of input ? psernaalvarez Programming 3 02-16-2008 02:35 PM
label at the end of compuound statement error isuck@linux Linux - Software 3 08-31-2007 02:49 PM
Sntax error at the end of input mihireng Programming 2 07-07-2006 10:45 AM
syntax error at the end of input mihireng Programming 4 07-06-2006 10:08 PM
warning: deprecated use of label at end of compound statement abk4523 Programming 1 03-06-2005 09:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration