Hi there. I was trying out a relatively simple program to convert a line of text into a 2-D string array which each word in a different row but it isn't working.
The program is
#include <iostream>
void main()
{
int i, j, k=0;
char line[30]={"This is a test"}, temp[5][5];
for(i=0; line[k]!=NULL; i++)
for(j=0; line[k]!=" "; j++)
temp[i][j]=line[k++];
for(i=0; i<5; i++)
cout<<line[i];
}
This is the error that comes up:
\Desktop\test.cpp(7) : error C2446: '!=' : no conversion from 'char *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast\Desktop\test.cpp(7) : error C2040: '!=' : 'int' differs in levels of indirection from 'char [2]'
This is the line in which the error lies
for(j=0; line[k]!=" "; k++)
The error goes away if I add an asterisk before the " " like so:
for(j=0; line[k]!=*" "; k++)
The program runs but doesn't end which I'm assuming is because of an infinite loop.
I'm a C++ beginner and any help would be much appreciated.