So whats this all about then?
It's in the following line of code:
cout << "Too many... can't be more than ";<<max_r<<" !";
So whats this all about then?
It's in the following line of code:
cout << "Too many... can't be more than ";<<max_r<<" !";
Change:
cout << "Too many... can't be more than ";<<max_r<<" !";
to
cout << "Too many... can't be more than "<<max_r<<" !";
Cheers ArseMan , but...
Changed that but still same error code apppearing??
189: unterminated character constant
Is there anywhere that describes the compile error codes in detail, I'm using Bloodsheds: 'Dev-C++'.
Show more of your code because that statement compiles fine for me and im using Dev-c++.
Cheers for the help ArseMan its greatly appreciated.
Here is the whole program, and have you got a simular programs to this as I'm new to C++ and would like some source code to look through and hopefully learn. As I've got loads of books but find looking at source code I can understand it better.
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <fstream.h>
#include <io.h>
//--- Some global variables
typedef unsigned int manname;
const manname max_r=100; //maximum records
const manname max_n=30; //maximum length of a name
char *book[max_r];
void Initialize()
{
//create the array
for(manname a=0;a<max_r;a++)
book[a]=new char[max_n];
}
//---------------------------
//--- Functions definitions
void fMenu();
void fAfterInput(manname count);
//-------------------------
int compare(const void *i, const void *j)
{
return( strcmp(*(char **)i, *(char **)j) );
}
void fInputFile()
{
char string[40];
char file[30];
cout << "Enter filename to input: ";
cin >> file;
ifstream ReadFile(file);
if(ReadFile)
{
while(!ReadFile.eof())
{
ReadFile >> string;
cout << string<<endl;
}
fMenu();
}
else
{
cout << "Error reading file!\n";
cout << "Make sure it exists...\n\n";
fInputFile();
}
}
void fSaveFile(manname count)
{
char filename[30];
char inputstring[200];
cout << "Enter filename: ";
cin >> filename;
ifstream GetOld(filename);
ofstream SFile("temporary.txt");
while(!GetOld.eof())
{
GetOld >> inputstring;
SFile << inputstring << endl;
}
GetOld.close();
for(ui f=0;f<count;f++)
SFile << book[f]<<endl;
SFile.close();
_unlink(filename);
rename("temporary.txt",filename);
cout << "Saved!\n";
fAfterInput(count);
//GetOld.close();
}
void fSeeTheRecords(manname count)
{
for(manname b=0;b<count;b++)
cout<<book[b]<<endl;
fAfterInput(count);
}
void fSortTheRecords(manname count)
{
qsort(book,max_r, sizeof(char *),compare);
cout << endl;
char ask_u[5];
cout << "Do you want to see the sorted records?";
cin >> ask_u;
if(ask_u[0]=='y')
{
fSeeTheRecords(count);
}
else
fAfterInput(count);
}
void fAfterInput(manname count)
{
manname wanted;
cout << "/----------------------------------\" << endl;
cout << "| 1) Sort The Records |" << endl;
cout << "| 2) See The Entered Records |" << endl;
cout << "| 3) Save The Records To A File |" << endl;
cout << "| 4) Go Back To The Menu |" << endl;
cout << "| 5) Exit |" << endl;
cout << "\----------------------------------/" << endl;
cout << endl;
cin >> wanted;
if(wanted > 5)
{
cout << "Wrong Input\n";
fAfterInput(count);
}
else
{
switch(wanted)
{
case 1:
fSortTheRecords(count);
break;
case 2:
fSeeTheRecords(count);
break;
case 3:
fSaveFile(count);
break;
case 4:
fMenu();
break;
case 5:
exit(0);
break;
}
}
}
//--- Getting the input from the user
void fGetInput(manname max_entered)
{
cin.getline(book[0],max_n);
for(manname c=0;c<max_entered;c++)
{
cout<<"Enter entry #"<<c+1<<" : ";
cin.getline(book[c],max_n);
}
fAfterInput(max_entered);
}
//----------------------------
void fUserInput()
{
manname num_rec;
char answer[5];
cout << "How many records you want to enter? : ";
cin >> num_rec;
if(num_rec > max_r)
{
cout << "Too many... can't be more than "<<max_r<<" !";
cout << "Do you want to try again?";
cin >> answer;
if(answer[0]=='y')
fUserInput();
else
{
cout << "Do you want to go back to the menu?";
cin >> answer;
if(answer=="y")
fMenu();
else
exit(0);
}
}
else
fGetInput(num_rec);
} //---End of fUserInput()
//--- Menu
void fMenu()
{
manname wanted;
cout << "---------------------------------" << endl;
cout << "| 1) Input Specified File |" << endl;
cout << "| 2) Enter Records |" << endl;
cout << "| 3) Exit Program |" << endl;
cout << "---------------------------------" << endl;
cout << endl;
cin >> wanted;
if(wanted > 3)
{
cout << "Wrong input!\n";
fMenu();
}
else
{
switch(wanted)
{
case 1:
fInputFile();
break;
case 2:
fUserInput();
break;
case 3:
exit(0);
break;
}
}
}
void main()
{
Initialize();
fMenu();
}
The actuall error that you had was at this section of code
there also an error at this section of codeCode:void fAfterInput(manname count) { manname wanted; cout << "/----------------------------------" << endl; // took out the \" because \" tells the compiler // to print out the character " and not termanate the string cout << "| 1) Sort The Records |" << endl; cout << "| 2) See The Entered Records |" << endl; cout << "| 3) Save The Records To A File |" << endl; cout << "| 4) Go Back To The Menu |" << endl; cout << "| 5) Exit |" << endl; cout << "----------------------------------/" << endl; // took out the \- because the \ tells the // compiler that whatever comes next is a special character // such as \n wich means newline or \t wich means tab cout << endl; cin >> wanted;
Code:void fSaveFile(manname count) { char filename[30]; char inputstring[200]; cout << "Enter filename: "; cin >> filename; ifstream GetOld(filename); ofstream SFile("temporary.txt"); while(!GetOld.eof()) { GetOld >> inputstring; SFile << inputstring << endl; } GetOld.close(); for(ui f=0;f<count;f++) // the compiler dosn't know what ui is SFile << book[f]<<endl;
oops I forgot to sign in that was me who posted that!