compare the char & substr()
I compare the chars:
char cInLine[i][30];
...
if((cInLine[i][2]==":")&&(cInLine[i][5]==":")&&(cInLine[i][11]==";")&&(cInLine[i][14]==":")&&(cInLine[i][17]==":"))
{ .....},
but, I is told that "'==' : no conversion from 'char *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
e:\My Study\My VC++\temp for caption of movie\caption\captionDlg.cpp(260) : error C2040: '==' : 'int' differs in levels of indirection from 'char [2]' ",
by the way, how can I get some chars from a string of cInLine[i]?
thanks!
Re: compare the char & substr()
Change your string to be ':' not ":"
cInLine[i][2]==':'
":" is a null terminated string and therefore is 2 bytes long and you can't compare that to a single character. ':' on the other hand IS a single character.
Re: compare the char & substr()
Thanks!
How about the second question? :)
Re: compare the char & substr()
Quote:
Originally Posted by xmasry
how can I get some chars from a string of cInLine[i]?
do you mean how you can get a character from one of the strings in cInLine?
to get character 5 from string 2, do something like:
Code:
char MyChar = cInLine[5][2];
Re: compare the char & substr()
Hello xmasry,
If you want a character (at position m, say) from cInLine[n], you can use cInLine[n][m]. If you want a group of characters (say p characters starting from position m) as string, you may have to do like this:
Code:
char* cPart = new char[p + 1];
if (cPart)
{
// Copies string and terminates with null
memmove(cPart, cInLine[n] + m, p);
cPart[p] = 0;
// Use string cPart
...
// Delete memory allocated
delete[] cPart;
}
A word of advice: Use std::string instead of char*. It is easier.
Regards.
Pravin.
28-04-2005.