Hi There,
I have to do this read a list of names from an input file of my own, In main() I declared a Namelist[][] object, read several names from thefile using redirection and then print out the list. I have to add the name to the list only if the name is not already there and the list is not full.I also have to check if the name exists with another method.I wrote these methds in a class NameList and used the object in main.
1-> I am having problem with the spaces in the file.When I read the contents and print them, it prints out the spaces as some junk chars.I really want to print only the names in the file.
2->I cannot get to write the add(char name[]) method which compares the names in the file with the list.
Here is my code:
#include<iostream.h>
#include<fstream>
#include <string.h>
using namespace stdin;
int main( int argc, char* argv[] )
{
char word[10][21];
Namelist List[10][21]=new NameList();
int i,j;
ifstream indata(argv[1]);
if(indata.is_open())
{ while(!indata.eof())
{
for(int i=0; i<10; i++) {
indata.getline(word[i],20,'\n');//the list shud have 10 names of each 20 chars long.The problem is it prints out even the spaces as some junk }
}
indata.close();
}
else cout << "Unable to open file";
for (i=0; i<10; i++) //loop to show the array
{
for (j =0; j <20; j++)
{
cout<<word[i][j];
}
cout<<endl;
}
bool isThere;
for(int i=0;i<10;i++)
{
isThere=strcmp(list[i],name[i]);
}
return 0;
}