I have finished editing the program but I still have a couple of errors that I can't figure out, please help

Errors:

Error 1 error C2601: 'split' : local function definitions are illegal \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\err\err\err.cpp 97
Error 2 fatal error C1075: end of file found before the left brace '{' at '.\err.cpp(82)' was matched \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\err\err\err.cpp 137

/* Specification:
Gilberto Sotomayor-Candelaria  
Lab 7 Exercise 3
Append and display records in a address database*/

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void menu(void);
void writeData(void);
void readData(void);
string * split(string, char);

const char FileName[] = "c:/TestAddress.txt";

int main ()
{
	menu();
	return 0;
} //end main

void menu(void)
{	
	char choice = ' ';
	cout << "\nWhat Would You Like To Do With These Records: \n\n";
	cout << "Append Records (A), Show Records (S), or Exit (E)\n"; 
	 cin >> choice;
	
	while(choice == 'A' || choice == 'S');
	{
		switch(choice)
		{
			case 'a':
			case 'A':
				writeData();
				break;
			case 's':
			case 'S':
				readData();
				break;
		}
		cout << "What Else Would You Like To Do?\n";
		cout << "Append Records (A), Show Records (S), or Exit (E)\n"; 
		 cin >> choice;
	}
}//end menu

void writeData(void)
{
char choice = 'Y';
string name = "";
string street = "";
string city = "";
string state = "";
string zipCode = "";
ofstream outMyStream(FileName, ios::app);
	do
	{
		cout << "\nEnter The Name: ";
		getline(cin, name);
		cout << "\nEnter The Street: ";
		getline(cin, street);
		cout << "\nEnter The City: "; 
		getline(cin, city); 
		cout << "\nEnter The State: "; 
		getline(cin, state);
		cout << "\nEnter The Code: "; 
		cin >> zipCode;

		outMyStream << name << "," << street << "," << city << "," << state << "," << zipCode;

		cout << "\nEnter another Record? (Y/N) ";
		cin >> choice;
	}
	while (choice == 'Y' || choice == 'Y' ); 
	outMyStream.close();
}//end write data

void readData(void)
{
	ifstream inMyStream (FileName);
	string lineBuffer;
	while (!inMyStream.eof() )
	{
		getline (inMyStream, lineBuffer, '\n');
		string *theFields = split(lineBuffer, ',');
		cout << "Name...... " << theFields[0] << endl;
		cout << "Street.... " << theFields[1] << endl;
		cout << "City...... " << theFields[2] << endl;
		cout << "State..... " << theFields[3] << endl;
		cout << "Zip code.. " << theFields[4] << endl;
}//end read data

string * split(string theLine, char theDeliminator)
{
	//Break theline into fields and save the fields to an array.
	//Each field will occupy one element in a character array.
	//theLine is a string with fields separated with theDeliminator character.
	//Assumes the last field in the string is terminated with a newline.
	//Useage: string *theFields = split(lineBuffer, ',');

	//determine how many splits there will be so we can size our array
	int splitCount = 0;
	for(int i = 0; i < theLine.size(); i++)
	{
		if (theLine[i] == theDeliminator)
		{
			splitCount++;
		}
	}
	splitCount++; //add one more to the count because there is not an ending comma
	//create an array to hold the fields
	string* theFieldArray;
	theFieldArray = new string[splitCount];
	//split the string into seperate fields
	string theField = "";
	int commaCount = 0;

	for(int i = 0; i < theLine.size(); i++)//read each character and look for the deliminator
	{
		if(theLine[i] != theDeliminator) 
		{
			theField += theLine[i]; //build the field
		}
		else //the deliminator was hit so save to the field to the array
		{
			theFieldArray[commaCount] = theField; //save the field to the array
			theField = "";
			commaCount++;
		}
	}
	theFieldArray[commaCount] = theField; //the last field is not marked with a comma...
	return theFieldArray;
} //end split

I think you're just not closing the while loop started on line 85.

I have updated my code but I feel it is not doing what it is intended. When I append it does not let me add a name to the record and when I try to see the record it just kicks me out the program. Can somebody tell me what I'm doing wrong

/* Specification:
Gilberto Sotomayor-Candelaria  
Lab 7 Exercise 3
Append and display records in a address database*/

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void menu(void);
void writeData(void);
void readData(void);
string * split(string, char);

const char FileName[] = "c:/TestAddress.txt";

int main ()
{
	menu();
	return 0;
} //end main

void menu(void)
{	
	char choice = ' ';
	cout << "\nWhat Would You Like To Do With These Records: \n\n";
	cout << "Append Records (A), Show Records (S), or Exit (E)\n"; 
	 cin >> choice;
	
	while(choice == 'A' || choice == 'S');
	{
		switch(choice)
		{
			case 'a':
			case 'A':
				writeData();
				break;
			case 's':
			case 'S':
				readData();
				break;
		}
		cout << "What Else Would You Like To Do?\n";
		cout << "Append Records (A), Show Records (S), or Exit (E)\n"; 
		 cin >> choice;
	}
}//end menu

void writeData(void)
{
	char choice = ' ';
	string name = "";
	string street = "";
	string city = "";
	string state = "";
	string zipCode = "";
	ofstream outMyStream(FileName, ios::app);

	do
	{
		cout << "\nEnter The Name: ";
		getline(cin, name);
		cout << "\nEnter The Street: ";
		getline(cin, street);
		cout << "\nEnter The City: "; 
		getline(cin, city); 
		cout << "\nEnter The State: "; 
		getline(cin, state);
		cout << "\nEnter The Zip Code: "; 
		getline(cin, zipCode);

		outMyStream << name << "," << street << "," << city << "," << state << "," << zipCode;

		cout << "\nEnter another Record? (Y/N) ";
		cin >> choice;
	}
	while (choice == 'Y' || choice == 'Y' ); 
	outMyStream.close();
}//end write data

void readData(void)
{
	ifstream inMyStream (FileName);
	string lineBuffer;
	while (!inMyStream.eof() )
	{
		getline (inMyStream, lineBuffer, '\n');
		string *theFields = split(lineBuffer, ',');
		cout << "Name...... " << theFields[0] << endl;
		cout << "Street.... " << theFields[1] << endl;
		cout << "City...... " << theFields[2] << endl;
		cout << "State..... " << theFields[3] << endl;
		cout << "Zip code.. " << theFields[4] << endl;
	}
}//end read data

string * split(string theLine, char theDeliminator)
{
	//Break theline into fields and save the fields to an array.
	//Each field will occupy one element in a character array.
	//theLine is a string with fields separated with theDeliminator character.
	//Assumes the last field in the string is terminated with a newline.
	//Useage: string *theFields = split(lineBuffer, ',');

	//determine how many splits there will be so we can size our array
	int splitCount = 0;
	for(int i = 0; i < theLine.size(); i++)
	{
		if (theLine[i] == theDeliminator)
		{
			splitCount++;
		}
	}
	splitCount++; //add one more to the count because there is not an ending comma
	//create an array to hold the fields
	string* theFieldArray;
	theFieldArray = new string[splitCount];
	//split the string into seperate fields
	string theField = "";
	int commaCount = 0;

	for(int i = 0; i < theLine.size(); i++)//read each character and look for the deliminator
	{
		if(theLine[i] != theDeliminator) 
		{
			theField += theLine[i]; //build the field
		}
		else //the deliminator was hit so save to the field to the array
		{
			theFieldArray[commaCount] = theField; //save the field to the array
			theField = "";
			commaCount++;
		}
	}
	theFieldArray[commaCount] = theField; //the last field is not marked with a comma...
	return theFieldArray;
} //end split

Never try to crete a file in the root folder of C: because you may not have persmissions to do that. Move it to a different folder that.


void main() -- main() always returns an integer, never void. Some compilers may permit void but that is non standard and will not compile with many compilers. So to be strictly according to C++ standards you must declare main as int main() , or with optional parameters.

After getting the menu choice in main() you need to flush the '\n' Enter key from the keyboard buffer. If you don't then the next getline() will not work. Read this thread about how to do that.


Here is why the loop doesn't work right
>>while (choice == 'Y' || choice == 'Y' );

One of those two 'Y' should be lower case :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.