M
Markus
Hi!
I've the follwoing in my C/C++-Program:
There's a struct defined as following:
struct t_datensatz {
char flag;
char ID;
char Tel[29];
};
..
..
int main void() {
t_datensatz ds[2];
ds[0].flag='1';
ds[0].ID='2';
strcpy(ds[0].Tel,"TelegrammmmmmmmmmmmmmmmmmmmmA");
cout << "OUT: " << ds[0].flag << ds[0].ID << ds[0].Tel << endl;
ds[1].flag='3';
ds[1].ID='4';
strcpy(ds[1].Tel,"TelegrammmmmmmmmmmmmmmmmmmmmB");
cout << "OUT: " << ds[1].flag << ds[1].ID << ds[1].Tel << endl;
ds[2].flag='5';
ds[2].ID='6';
strcpy(ds[2].Tel,"TelegrammmmmmmmmmmmmmmmmmmmmC");
cout << "OUT: " << ds[2].flag << ds[2].ID << ds[2].Tel << endl;
// This doesn't work, why??
for(int i=0;i<=2;i++)
cout << "OUT: " << ds.flag << ds.ID << " " <<
ds.Tel <<
endl;
}
Produced Output:
Ok, the first three lines are fine. But why does the for-statement not
work as it is intented to??? It should produce exactly the same output
as the "manual" cout-statements.
I guess the problem is "ds.Tel". What's wrong in that little
program?
Tnx,
Markus
I've the follwoing in my C/C++-Program:
There's a struct defined as following:
struct t_datensatz {
char flag;
char ID;
char Tel[29];
};
..
..
int main void() {
t_datensatz ds[2];
ds[0].flag='1';
ds[0].ID='2';
strcpy(ds[0].Tel,"TelegrammmmmmmmmmmmmmmmmmmmmA");
cout << "OUT: " << ds[0].flag << ds[0].ID << ds[0].Tel << endl;
ds[1].flag='3';
ds[1].ID='4';
strcpy(ds[1].Tel,"TelegrammmmmmmmmmmmmmmmmmmmmB");
cout << "OUT: " << ds[1].flag << ds[1].ID << ds[1].Tel << endl;
ds[2].flag='5';
ds[2].ID='6';
strcpy(ds[2].Tel,"TelegrammmmmmmmmmmmmmmmmmmmmC");
cout << "OUT: " << ds[2].flag << ds[2].ID << ds[2].Tel << endl;
// This doesn't work, why??
for(int i=0;i<=2;i++)
cout << "OUT: " << ds.flag << ds.ID << " " <<
ds.Tel <<
endl;
}
Produced Output:
OUT: 12TelegrammmmmmmmmmmmmmmmmmmmmA
OUT: 34TelegrammmmmmmmmmmmmmmmmmmmmB
OUT: 56TelegrammmmmmmmmmmmmmmmmmmmmC
OUT: 12 TelegrammmmmmmmmmmmmmmmmmmmmA34TelegrammmmmmmmmmmmmmmmmmmmmB56TelegrammmmmmmmmmmmmmmmmmmmmC
OUT: 34 TelegrammmmmmmmmmmmmmmmmmmmmB56TelegrammmmmmmmmmmmmmmmmmmmmC
OUT: 56 TelegrammmmmmmmmmmmmmmmmmmmmC
Ok, the first three lines are fine. But why does the for-statement not
work as it is intented to??? It should produce exactly the same output
as the "manual" cout-statements.
I guess the problem is "ds.Tel". What's wrong in that little
program?
Tnx,
Markus