Hi i'm new to coding and am having a problem with a program i'm making, i have got it down to 4 errors which are on a single line, but i have no idea was wrong and how to solve it.
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <string>
#include <fstream>
using namespace std;
# define MAX 100
struct addr {
char name[30] ;
char street[40] ;
char town[20] ;
char county[20] ;
char code[10] ;
} list[MAX];
void enter(), save(), load();
int del(), search(), show_list(), find_free();
int menu_select(), find(char *name), display(int i), init_list(), inputs(char *prompt , char *s , int count);
int main()
{
int choice;
init_list();
for(;;)
{
choice = menu_select();
switch(choice)
{
case '1': enter();
break;
case '2':del();
break;
case '3':search();
break;
case '4':show_list();
break;
case '5':save();
break;
case '6':load();
break;
}
cout << "\n";
}
return 0;
}
void enter()
{
int i;
for(;;) {
i = find_free();
if(i<0) {
printf("list full\n");
return;
}
inputs("enter name: ", list[i].name,30);
if(!*list[i].name) break;
inputs("enter street: ", list[i].street, 40);
inputs("enter town: ", list[i].town, 20);
inputs("enter county: ", list[i].county, 20);
inputs("enter Postal code: ", list[i].code, 10);
}
}
int del()
{
int i;
char str[255];
inputs("enter name: " , str , 30);
i = find(str);
if (i>=0) *list[i].name = '\0' ;
else printf("not found\n") ;
}
int search()
{
int i;
char name[30];
inputs("enter name to find: " , name , 30);
if ((i=find(name))<0)
printf("not found\n");
else
display(i);
}
int show_list()
{
int i;
for(i=0; i<MAX; i++)
{
if(*list[i].name)
{
display(i);
printf("\n\n");
}
}
printf("\n\n");
}
void save()
{
FILE *fp;
if ( (fp=fopen("mlist" , "wb")) == NULL) {
printf("cannot open file\n");
return;
}
printf("\nsaving file\n");
fwrite(list , sizeof list , 1 , fp);
if (ferror(fp))
printf("An error occurred while writing file.\n");
fclose(fp);
}
void load()
{
FILE *fp;
if ( (fp=fopen("mlist" , "rb")) == NULL) {
printf("cannot open file\n");
return;
}
printf("\nloading file\n");
fread(list , sizeof list , 1 , fp);
if (ferror(fp))
printf("An error occurred while reading file.\n");
fclose(fp);
}
int find_free()
{
register int i;
for(i=0; i<MAX; i++)
if(!*list[i].name) return i;
return -1;
}
int menu_select()
{
char s[80];
int c;
printf("1. Enter a name\n") ;
printf("2. Delete a name\n") ;
printf("3. List the File \n");
printf("4. Search\n") ;
printf("5. Save the file\n") ;
printf("6. Load the file\n") ;
printf("7. Quit\n") ;
do {
printf("\nEnter your choice: ");
gets(s);
c = atoi(s);
} while(c<0 || c>7);
return c;
}
int find(char *name)
{
int i;
for(i=0 ; i<MAX ; i++)
if(!strcmp(name ,list[i].name)) break;
if(i==MAX) return -1;
else return i;
}
int display(int i)
{
printf("%s\n" , list[i].name);
printf("%s\n" , list[i].street);
printf("%s\n" , list[i].town);
printf("%s\n" , list[i].county);
printf("%s\n" , list[i].code);
}
int init_list()
{
register int i;
for (i=0 ; i<MAX ; i++)
*list[i].name = '\0';
}
int inputs(char *prompt , char *s , int count)
{
char str[255];
do {
printf(prompt);
gets(str);
if(strlen(str)>=count) printf("\ntoo long\n");
} while(strlen(str)>=count);
strcpy(s , str);
}
the main errors are in with "for(i=0; i<MAX; i++)" this part of the code but i can't see whats wrong.
the errors are:
missing ')' before identifier 'i'
syntax error : ';'
syntax error : ')'
syntax error : missing ';' before '{'
I've tried just typing what it says is wrong and that jsut ends up giving me more errors so there's prob something basic i'm missing but i've been trying for hours to sort it out with no luck, hopfully someone can help.
thanks