Problem with buffer output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// prata 9-3 bufer new.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "iostream"
#include <string>
#include <conio.h>
#include <new>

struct chaff
{
	char dross[20];
	int slag;
};

char buffer[512];

void show_chaff(chaff *, short);

int _tmain(int argc, _TCHAR* argv[])
{
	const short s_ar_size=2;
	using std::cout;
	using std::cin;
	using std::endl;
	chaff *chaff_ar=new (buffer) chaff[s_ar_size];
	show_chaff(chaff_ar,s_ar_size);
	for (int i=0; i<s_ar_size; i++)
	{
		cout<<"Enter dross\n";
	    cin.getline(chaff_ar[s_ar_size].dross,19);
		cout<<"Enter slag\n";
		while (!(cin>>chaff_ar[s_ar_size].slag))
		 {
			 cin.clear();
			 cin.ignore(64,'\n');
			 cout<<"Enter rigt value!\n";
		 }
		cin.get();//number input - take '\n'
	}
	//show_chaff(chaff_ar,s_ar_size);
	for (int i=0; i<s_ar_size; i++)
		std::cout<<chaff_ar[i].dross<<"\t"<<chaff_ar[i].slag<<"\n";
	getch();
	return 0;
}

void show_chaff(chaff *ch_ar, short s)
{
	for (int i=0; i<s; i++)
		std::cout<<ch_ar[i].dross<<"\t"<<ch_ar[i].slag<<"\n";
}

It works, but it output anything - please give me a advice
Worked for me. I had to make some minor adjustments because of the pre-compiled headers, but worked fine after.

Output:

0
0
Enter dross
3
Enter slag
5
Enter dross
4
Enter slag
1
0
0
Yes, but I need to output
3 5
4 1
why it output
0
0
?
I guess I don't know what this program is suppose to do. You can input 3 5 and 4 1, but there's nothing in your code that is doing anything with the numbers. What is this program suppose to accomplish?
OMG!
I just have understood!
Thanks a lot!
Topic archived. No new replies allowed.