Hi,
I wrote the following code and found there are 3 logical errors:
1) When I input the URL like www.abc.com www.xyz.com (there is a space between these 2 domains), it will skip the input title entry and treat the second string as the title.
2) I entered the www.abc.com for URL. I input 2 strings like www.xyz.com www.yahoo.com for the title page (A space % 2 strings also). It will list out the first record like:
www.abc.com www.xyz.com
without displaying ww.yahoo.com and unable to input next record.
3) It shows 10 arrays every time even some of them did not have records. e.g. I just input 3 records, it will show 7 blank records.
How I can fix them?
Regards
gogo
Here is the code for implementation:
bookmarks::bookmarks() //constructor
{
int i;
for(i = 0; i < SIZE; i++)
{
url[i] = "";
title[i] = "";
}
}
void bookmarks::setbookmarks()
{
char a = 0;
int k = 0;
int j = 0;
do
{
cout << "Input URL : ";
cin >> url[k++];
cout << endl;
cout << "Input Title : ";
cin >> title[j++];
cout << endl;
cout << "Do you want to add more (Y/N)? ";
cin >> a;
cout << endl;
}while (j<SIZE && tolower(a)=='y');
}
void bookmarks::getbookmarks()
{
int i;
cout << endl;
cout << "**********************************" << endl;
cout << endl;
for (i = 0; i < SIZE; i++)
{
cout << "URL : " << url[i] << " " << "Title : " << title[i] << endl;
}
cout << endl;
}
Here is the main program:
void main()
{
bookmarks x;
x.setbookmarks();
x.getbookmarks();
}