Dear Rooters
The following macro CharArray() below runs perfectly fine as macro,
but I am not able to compile it. I get the error:
"assignment to `char' from `const char *' lacks a cast"
However, casting "str" to "char(str)" causes a different error.
Since I have to store letters read from an input file as character
array "arrStr" in my code, my question is:
What is wrong in my code example?
How do I have to rewrite the code?
Since I have to use "sscanf()", how do I access "str"?
Thank you in advance for your help.
(MacOSX running root 3.03/05)
Best regards
Christian
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
C.h.r.i.s.t.i.a.n. .S.t.r.a.t.o.w.a
V.i.e.n.n.a. .A.u.s.t.r.i.a
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
//-----------CharArray---------------
void CharArray()
{
char str = "A";
char *arrStr = new char[20];
// initialize array
Int_t i;
for (i=0; i<20; i++) {
arrStr[i] = str;
// arrStr[i] = str + i;
}
for (i=0; i<20; i++) {
cout << arrStr[i];
}
cout << endl;
// read letters from input
char nextline[128];
ifstream input;
input.open("ABC.txt", ios::in);
for (i=0; i<20; i++) {
input.getline(nextline, 128);
sscanf(nextline, "%c \n", &str);
arrStr[i] = str;
}
input.close();
for (i=0; i<20; i++) {
cout << arrStr[i];
}
cout << endl;
delete [] arrStr;
}//CharArray
//------------ABC.txt---------------
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
//-----------------------------------
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:54 MET