syntax error at end of input
I have this file with c code and i;m getting syntax error at end of input this error..Could someone help me??
Code:
#include "Types.h"
void show_main_menu(int);
account* create_new_owner_account(void);
account *create_new_traveller_account(void);
account* kratisi(void);
account* traveller_action(int act2);
char input[1000];
char buffer[1500];
void show_main_menu(int sd)
{
printf("Eiste idiokthths parking (pieste 1) h' eiste taksidiotis(pieste 7) ");
get_input: //label
printf("client> ");
fgets(input, 100, stdin);
if(strlen(input) > 2) {
printf("La8os epilogh parakalw pieste ksana\n");
goto get_input;
}
switch(input[0]) {
case '1': {
printf("\n|----------------|\n");
printf("|------MENU------|\n");
printf("|----------------|\n");
printf("\n|---------------------|\n");
printf("1. Dhlwsh neou parking\n");
printf("|---------------------|\n");
printf("\n|------------------------------|\n");
printf("2. Provolh teleytaiwn krathsewn\n");
printf("|------------------------------|\n");
printf("----------------------\n\n");
printf("Grapste thn epilogh sas\n");
get_input1: //label
printf("client> ");
fgets(input, 100, stdin);
if(strlen(input) > 2) {
printf("La8os epilogh parakalw pieste ksana\n");
goto get_input1;
}//if
switch(input[0]) {
case '1':
if((write(sd, create_new_owner_account(), sizeof(account)) == -1)) {//klhsh synarthshs gia neo logariasmo
perror("write");
exit(1);
} //if
break;
case '2':
if((write(sd, owner_action(), sizeof(account)) == -1)) {//klhsh synarthshs gia tis leitourgies tou client
perror("write");
exit(1);
}//if
break;
}
break;//gia to case=idiokthths
case '7'://gia epilogh taksidioth
{
printf("\n|----------------|\n");
printf("\n-----MENU-----\n");
printf("|----------------|\n");
printf("\n|-----------------------------|\n");
printf("3. Dhmiourgia neou logariasmou.\n");
printf("|-----------------------------|\n");
printf("\n|------------------|\n");
printf("4. Krathsh parking \n");
printf("|------------------|\n");
printf("\n|-----------------------------|\n");
printf("5. Provolh stoixeiwn logariasmou");
printf("|-----------------------------|\n");
printf("\n|------------------|\n");
printf("6. Kata8esh xrhmatwn. \n");
printf("|------------------|\n");
printf("----------------------\n\n");
printf("Grapste thn epilogh sas\n");
get_input2: //label
printf("client> ");
fgets(input, 100, stdin);
if(strlen(input) > 2) {
printf("La8os epilogh parakalw pieste ksana\n");
goto get_input2;
}//if
switch(input[0]) {
case '3':
if((write(sd , create_new_traveller_account(), sizeof(account)) == -1)) {// klhsh synarthshs pou ftiaxnei neo logariasmo taksidioti
perror("write");
exit(1);
}//if
break;
case '4':
if((write(sd, kratisi(), sizeof(account)) == -1)); {//klhsh synarthshs gia krathsh
perror("write");
exit(1);
}//if
break;
case '5':
if(write(sd , traveller_account_action(SHOWT), sizeof(account)) == -1) {//klhsh synarthshs gia leitourgies taksidioti
perror("write");
exit(1);
}//if
break;
case '6':
if(write(sd , traveller_account_action(DEPOSIT), sizeof(account)) == -1) {
perror("write");
exit(1);
}//if
break;
case '7':
exit(0);
break;
default:
printf("Wrong choice.Please enter your choice again\n");
goto get_input2;
}//gia to case=taksidiotis
break;
}//gia th main_menu
account* create_new_owner_account(void)
{
account *new_owner_account; //deikths se domh typou account
new_owner_account = (account*)malloc(sizeof(account)); //dhmiourgia, sth mnhnh, mias domhs typou account.
new_owner_account->type=0;//orizoume oti eimaste se struct gia owner
name: //label
printf("Dwste to onoma tou parking(max 15 chars): ");
fgets(input, 100, stdin);
if(strlen(input) > 2) {//an o xrhsths edose onoma megalutero apo 2 grammata.
strncpy(new_owner_account->parking, input, 15); //antigrafoume thn eisodo tou xrhsth sto melos name ths domhs account.
new_owner_account->parking[15] = '\0'; //pros8etoume ton eidiko xarakthra pou shmainei to telos enos string.
}//if
else {//o xrhsths edose onoma me ena mono gramma opote tou leme na ksanadosei neo onoma.
printf("Prepei na dwsete ena onoma me to ligotero dyo grammata\n");
goto name;
}//else
description:
printf("Dwste perigrafh gia to parking (max 80 chars): ");
fgets(input, 100, stdin);
if(strlen(input) > 2) {//an o xrhsths edose onoma megalutero apo 2 grammata.
strncpy(new_owner_account->description_nametraveller, input, 80); //antigrafoume thn eisodo tou xrhsth sto melos name ths domhs account.
new_owner_account->description_nametraveller[80] = '\0'; //pros8etoume ton eidiko xarakthra pou shmainei to telos enos string.
}//if
else {//o xrhsths edose onoma me ena mono gramma opote tou leme na ksanadosei neo onoma.
printf("Prepei na dwsete mia perigrafh me to ligotero dyo grammata\n");
goto description;
}//else
price: //label
printf("Dwste thn timh tou parking ");
fgets(input, 100, stdin);
if(strlen(input) <= 1) {//an o xrhsths pathsei enter xoris na dosei kapoio noumero tou leme na ksanadosei.
printf("Prepei na dwsete mia timh me to ligotero ena pshfio!\n");
goto price;
}//if
int i;
/* elegxoume an h eisodos tou xrhsth periexei mono noumera allios ton parapempume na ksanadosei kainourgia eisodo. */
for(i=0; i<strlen(input)-1; i++) {
if(isdigit(input[i]) == 0) {//einai pshfio?
printf("La8os timh mono ari8moi!\n");
goto price;
}//if
}//for
/* an h eisodos htan egkyrh metatrepoume meso ths atoi to alfari8mitiko
* se int kai to apo8hkeuoume sto melos balance ths domhs account. */
new_owner_account->price_logariasmos = atoi(input);
new_owner_account->positions = 10;//arxika exoume 10 eley8eres 8eseis
new_owner_account->all_transactions = 0; //o ari8mos ton synnallagon arxika einai 0
int j;
/* arxikopoioume to melos type, ths domhs transaction pou me th seira ths
* einai melos ths domhs account, me thn sta8era UNKNOWN. To kanoume ayto
* gia na boh8h8oume ston elegxo pou kanoume apo ton server. */
for(j=0; j<20; j++)
new_owner_account->pinakas[j].type = UNKNOWN;
new_owner_account->action = CREATE_ACCOUNT;
return new_owner_account;
}//gia th create_owner
account *create_new_traveller_account(void)
{
account *new_traveller_account;
new_traveller_account = (account*)malloc(sizeof(account)); //dhmiourgia, sth mnhnh, mias domhs typou account.
new_traveller_account->type=1;//orizoume oti eimaste se traveller
name1: //label
printf("Dwste to onoma tou taksidioti (max 40 chars): ");
fgets(input, 100, stdin);
if(strlen(input) > 2) {//an o xrhsths edose onoma megalutero apo 2 grammata.
strncpy(new_traveller_account->description_nametraveller, input, 40); //antigrafoume thn eisodo tou xrhsth sto melos name ths domhs account.
new_traveller_account->description_nametraveller[80] = '\0'; //pros8etoume ton eidiko xarakthra pou shmainei to telos enos string.
}//if
else {//o xrhsths edose onoma me ena mono gramma opote tou leme na ksanadosei neo onoma.
printf("Prepei na dwsete onoma me toulaxiston dyo xarakthres\n");
goto name1;
}//else
balance: //label
printf("Dwste to arxiko ypoloipo ");
fgets(input, 100, stdin);
if(strlen(input) <= 1) {//an o xrhsths pathsei enter xoris na dosei kapoio noumero tou leme na ksanadosei.
printf("Prepei na dwsete ena ari8mo me to ligotero ena pshfio\n");
goto balance;
}//if
int i;
/* elegxoume an h eisodos tou xrhsth periexei mono noumera allios ton parapempume na ksanadosei kainourgia eisodo. */
for(i=0; i<strlen(input)-1; i++) {
if(isdigit(input[i]) == 0) {//einai pshfio?
printf("La8os timh, prepei na periexei mono ari8mous!\n");
goto balance;
}//if
}//for
/* an h eisodos htan egkyrh metatrepoume meso ths atoi to alfari8mitiko
* se int kai to apo8hkeuoume sto melos balance ths domhs account. */
new_traveller_account->price_logariasmos = atoi(input);
new_traveller_account->all_transactions = 0; //o ari8mos ton synnallagon arxika einai 0
int j;
/* arxikopoioume to melos type, ths domhs transaction pou me th seira ths
* einai melos ths domhs account, me thn sta8era UNKNOWN. To kanoume ayto
* gia na boh8h8oume ston elegxo pou kanoume apo ton server. */
for(j=0; j<4; j++)
new_traveller_account->pinakas[j].type = UNKNOWN;
new_traveller_account->action = CREATE_ACCOUNT; //h energeia edo einai dhmiourgia logariasmou
/* epistrefoume ena deikth typou account pou deixnei ston neodhmiourgh8enta
* logariasmo me ta stoixeia pou edose o xrhshs. */
return new_traveller_account;
}//create_new_traveller
account* owner_action(int act)
{
account *owner_action; //deikths se domh typou account
owner_action = (account*)malloc(sizeof(account)); //dhmiourgia, sth mnhnh, mias domhs typou account.
name3: //label
printf("\n Dwste onoma parking pou sas endiaferei.\n");
fgets(input, 100, stdin);
if(strlen(input) > 2) {//an o xrhsths edose onoma megalutero apo 2 grammata.
strncpy(owner_action->parking, input, 15); //antigrafoume thn eisodo tou xrhsth sto melos name ths domhs account.
owner_action->parking[15] = '\0'; //pros8etoume ton eidiko xarakthra pou shmainei to telos enos string.
}//if
else {//o xrhsths edose onoma me ena mono gramma opote tou leme na ksanadosei neo onoma.
printf("Prepei na dwsete ena onoma me to ligotero dyo grammata\n");
goto name3;
}
//strncpy(owner_action->parking, input, 15);
return owner_action;
}//owner action
account* kratisi(void)
{
account *kratisi_search;
kratisi_search = (account*)malloc(sizeof(account));
name4: //label
printf("Dwste to onoma tou taksidioti (max 40 chars): ");
fgets(input, 100, stdin);
if(strlen(input) > 2) {//an o xrhsths edose onoma megalutero apo 2 grammata.
strncpy(kratisi_search->description_nametraveller, input, 40); //antigrafoume thn eisodo tou xrhsth sto melos name ths domhs account.
kratisi_search->description_nametraveller[80] = '\0'; //pros8etoume ton eidiko xarakthra pou shmainei to telos enos string.
}//if
else {//o xrhsths edose onoma me ena mono gramma opote tou leme na ksanadosei neo onoma.
printf("Prepei na dwsete onoma me toulaxiston dyo xarakthres\n");
goto name4;
}//else
kratisi_search->action=SHOW;
return kratisi_search;
}//kratisi
account* traveller_action(int act2)
{
account *account_to_search; //deikths se domh typou account.
account_to_search = (account*)malloc(sizeof(account));
account_to_search->action = act2;
if(act2==SHOWT) {
name5:
printf("\nDwste to onoma tou taksidioti pou sas endiaferei.\n");
fgets(input, 100, stdin);
if(strlen(input) > 2) {//an o xrhsths edose onoma megalutero apo 2 grammata.
strncpy(account_to_search->description_nametraveller, input, 40); //antigrafoume thn eisodo tou xrhsth sto melos name ths domhs account.
account_to_search->description_nametraveller[80] = '\0'; //pros8etoume ton eidiko xarakthra pou shmainei to telos enos string.
}//if
else {//o xrhsths edose onoma me ena mono gramma opote tou leme na ksanadosei neo onoma.
printf("Prepei na dwsete onoma me toulaxiston dyo xarakthres\n");
goto name5;
}//else
strncpy(account_to_search->description_nametraveller, input, 40);
account_to_search->description_nametraveller[80] = '\0';
}
if(act2==DEPOSIT) {
amount: //label
printf("Ti poso 8elete na kata8esete: ");
fgets(input, 100, stdin);
if(strlen(input) <= 1) {
printf("Prepei na dwsete ari8mo me dyo toulaxiston pshfia!\n");
goto amount;
}
int j;
for(j=0; j<strlen(input)-1; j++) {
if(isdigit(input[j]) == 0) {
printf("La8os, to poso prepei na periexei mono ari8mous!\n");
goto amount;
}
}
/* efoson o xrhsths edose egkuro poso(dhladh mono ari8mous) to metatrepoume
* se int meso ths atoi kai to apo8hkeuoume sto melos amount tou account. */
account_to_search->price_logariasmos = atoi(input);
}
return account_to_search;
}//gia traveller action
int main(void)
{
int socket_desc, len, t; //metablhtes gia ta sockets.
struct sockaddr_un remote; //domh gia th die8unsh tou socket tou server.
if((socket_desc = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { //dhmiourgia tou socket tou client.
perror("socket");
exit(1);
}
printf("Trying to connect...\n");
remote.sun_family = AF_UNIX;
strcpy(remote.sun_path, SOCK_PATH);
len = strlen(remote.sun_path) + sizeof(remote.sun_family);
/* klhsh systhmatos gia th syndesh tou client kai tou server meso socket. */
if(connect(socket_desc, (struct sockaddr *)&remote, len) == -1) {
perror("connect");
exit(1);
}
printf("Connected.\n");
while(!feof(stdin)) {
/* kaloume thn synarthshshow_main_menu() me orisma to descriptor tou socket pou dhmiourghsame. */
show_main_menu(socket_desc);
/* diabazei kai apo8hkeuei ston pinaka buffer to mhnyma pou stelnei o server.
* an to mhkos tou string mhnymatos pou esteile o server einai 8etiko to ektyponoume. */
if((t = read(socket_desc, buffer, 300)) > 0) {
buffer[t] = '\0';
printf("server>\n%s", buffer);
exit(0);
}
else {
if(t < 0) perror("read"); //o server esteile mhnyma me arnhtiko mhkos == error.
else printf("Server closed connection\n"); //o server esteile keno mhnyma.
exit(1);
}
}
close(socket_desc); //kleinoume th sundesh client kai server kleinontas to socket.
return 0;
}