amozart
March 25th, 2003, 09:35 PM
I have an && condition in my parseWords function below. The first half works. The second half works standing alone without the first portion and without &&. But it won't work in the && condition to terminate my for loop. I am trying to teach myself Visual C++ using Ivor Horton's Visual C++ 6 book. The answer gives an identical logic statement as mine although the program and data structures differ.
//Ex5_5.cpp
//
#include<iostream>
using namespace std;
void parseWords(char array[]);
int main(void)
{
const int MAX = 80;
char string[MAX];
cout << "Enter a string: ";
cin.getline(string,MAX,'\n');
cout << string << endl;
parseWords(string);
return 0;
}
void parseWords(char array[])
{
static int count = 0;
const int MAX=80;
char temp[MAX] = {" "};
for(int i = count; array[i] != ' ' && array[i] != '\0'; i++) // This
same logic statement appears in the textbook's answer section, but it
doesn't work for me
{
temp[i] = array[i];
count++;
cout << i;
cout << temp[i];
}
cout << endl << "testing" <<endl;
count++;
cout << count << endl;
if(array[count] != '\0')
parseWords(array);
}
//Ex5_5.cpp
//
#include<iostream>
using namespace std;
void parseWords(char array[]);
int main(void)
{
const int MAX = 80;
char string[MAX];
cout << "Enter a string: ";
cin.getline(string,MAX,'\n');
cout << string << endl;
parseWords(string);
return 0;
}
void parseWords(char array[])
{
static int count = 0;
const int MAX=80;
char temp[MAX] = {" "};
for(int i = count; array[i] != ' ' && array[i] != '\0'; i++) // This
same logic statement appears in the textbook's answer section, but it
doesn't work for me
{
temp[i] = array[i];
count++;
cout << i;
cout << temp[i];
}
cout << endl << "testing" <<endl;
count++;
cout << count << endl;
if(array[count] != '\0')
parseWords(array);
}