JUnk value
why does it show junk value for name.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include<iostream>
#include<conio.h>
using namespace std;
struct part
{
char name[10];
int number;
};
void display (part p1)
{
cout<<p1.name<<endl;
cout<<p1.number<<endl;
}
int main()
{
part show;
cin>>show.name;
cin>>show.name;
display(show);
getch();
}
|
Because it's not null terminated. Fill name with zeroes before reading to it
Topic archived. No new replies allowed.