0

Actually you posted this:
You told me to increment it once more when I was already incrementing it once after the j loop.

Ok, I can understand how that could be interpreted differently. I meant:

for( over the i's)
    {
        for (over the j's, incrementing k also)
        {

        }
        //we've gone through one cycle of j's, so we've found a word
        k++;  //now increment
    }


Hmm alright, do I put that bit of code within the for loop or in the place where I'm incrementing k but just before it. Also, what does this bit of code do exactly? I haven't come across something like std::cout while I'm learning C++.

That's how cout and endl are written with their fully qualified name. In standard C++ namespaces are used to allow you isolate two functions/classes/etc. that might have the same name. I suspect you might be using a prestandard compiler. Cout, endl, cin, etc. are all under the namespace "std." So, if I create a my own cout method under the namespace jonsca, then I can use jonsca::cout and std::cout to tell the difference. Some people use a "using" statement to bring all of the members from one namespace into the global namespace (like using namespace std; )

So, you know what cout and endl are for, see if you can find a good spot in your code to output what you've just assigned to your array.

Edited by jonsca: n/a

0

Yes, I am using a fairly old compiler (visual c++ 6.0). Thanks for your help; I'll try it out and see how it goes.

0

After working with your original code that you posted I see you have a lot of problems keeping the counters i, j and k straight. Since you've had some time now to sort things out I'll post one solution. This code has one flaw -- white space at the beginning of the string will cause a minor problem.

#include <iostream>

int main()
{
    int i, j, k;
    char line[]="This is a test";
    char temp[5][5] = {0};
    for(i=j=k=0; line[k] != 0; j++)
    {
        if( isspace(line[k]) )
        {
            // skip all white spaces
            while( isspace(line[k]) )
            {
                k++;
            }
            i++; // increment line counter
            j = 0; // reset word counter
         }
        temp[i][j]=line[k++];
    }
    for(j = 0; j <= i; j++)
        std::cout<<temp[j] << '\n';
    std::cin.get();
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.