kux 55 Junior Poster

you did not allocate memory for the int* Tests variable.

the thing is I have a

testScores = new int[numTests];

but you don't use that nowhere

Now, the thing is like this
Reading your program what you actually try to do is iterate through each student and give to him numTests marks. That means the purpose of int* Tests is to point at the start of an array of numTests elements. That means at each iteration of the outer for you need to allocate memory numTests ints in you int* Tests pointer.

Your program should look like this in oder to just work:

struct studInfo
{
char Name[31];
short Idnum;
int* Tests;
float avg;
char grade;
};

void main()
{
	short numTests, numStudents;
	studInfo* student;
	int* testScores;

	cout << "How many Students? : ";
	cin >> numStudents;
	cout << "\nHow many test scores? : ";
	cin >> numTests;

	student = new studInfo[numStudents];

	for ( int i = 0; i < numStudents; i++ )
	{
		cout << "\nEnter ID for student " << (i + 1) << ": ";
		cin >> student[i].Idnum;

		testScores = new int[numTests];

		for ( int j = 0; j < numTests; j++ )
		{
			cout << "\nEnter test score " << (j + 1) << " for student " << i + 1 << ": ";
			//put the result at tre corresponding position in the array
			cin >> *(testScores + j); //or …
skatamatic commented: Helpful +2
kux 55 Junior Poster

hi all,

plesae any one can send me c++ code for radix-2 Fast Fourier Transform..

my email: << email id snipped >>

:) www.google.com
enjoy

William Hemsworth commented: nice link :] +4
kux 55 Junior Poster
int howmuchIread = 0;
	while ( ( howmuchIread = fread ( buffer, 1, READSIZE, fp ) )  != 0 )
	{
		buffer[ howmuchIread ] = 0; //place terminal character to avoid overruns

I hope you realize that the code in the last line above will likely cause buffer overflow. Lets say howmuchIread == READSIZE, which is the same as sizeof(buffer). Then buffer[howmuchIread] will be one byte beyond the end of the buffer.

if u look closer at the code, u will see that buffer is buffer[BUFFSIZE], and BUFFSIE = READSIZE + 1, so... no overrun there :)

Ancient Dragon commented: Yes I missed that :) +36
kux 55 Junior Poster

Hi, I would like to ask you for help in converting this code from C to C++. It's my little friend 's homework, but I can't help him 'cause I know nothing about C :( In fact, I just can't figure the "scanf" part out, I think the other part is similar to C++. Thanks in advance !
[
#include <stdio.h>
#include <string.h>
void main()
{
int i,br=0,d=0;
char r[200];
printf("Vnesete Recenica\n");
gets(r);
d=strlen(r);
for(i=0;i<=d;i++)
{
if((r=='n')&&(r[i+1]=='o'))
{
r=' ';
r[i+1]=' ';
br++;
}
}
printf("Vo Vasata recenica se pronajdeni i izbrisani %d no zborovi\n",br);
scanf("%d",&i);
}

]

#include <iostream>
#include <string>

void main()
{
	int i,br=0,d=0;
	//char r[200];
	std::string r;
	//printf("Vnesete Recenica\n");
	std::cout<<"Vnesete Recenica\n"<<std::endl;
	//gets(r);
	std::cin>>r;
	//d=strlen(r);
	//for(i=0;i<=r.length();i++)
	/*
	for(i=0;i<r.length() - 1 ;i++) //THIS WAS INCORRECT IN THE 1st IMPLEMENTATION  TOO, BUFFER OVERRUN !!
	{
		if((r.at(i)=='n')&&(r.at(i+1)=='o'))
		{
			r[i]=' ';
			r[i+1]=' ';
			br++;
		}
	}
	*/
	std::string::size_type poz = -1;
	while ( true )
		if (  ( poz = r.find( "no", poz + 1 ) ) != std::string::npos )
			br++;
		else 
			break;
	

	//printf("Vo Vasata recenica se pronajdeni i izbrisani %d no zborovi\n",br);
	std::cout<<"Vo Vasata recenica se pronajdeni i izbrisani "<<br<<" no zborovi\n"<<std::endl;
	//scanf("%d",&i);
	std::cin>>i;
}

the last scanf/cin is placed there so that the program won't end untill the user sees the output and presses some key.
I placed the old C implementation between coments. It …

kux 55 Junior Poster

Actually, it is possible. You need to use token concatenation. #define DEFINE_FUNC( n ) void func_ ## n() You would use it in the normal way: DEFINE_FUNC( 12 ); The preprocessor would turn that into: void func_12(); While I can't imagine why you want to do this, there are, in fact, legitimate reasons to do token concatenation (which goes a long way into explaining why the preprocessor can do it at all).

Hope this helps.

true, what i meant to say is that if u have

DEFINE_FUNC (12)
the preprocessor should replace with 12 function declarations named func_1 func_2 ... func_12
so as Dave said, the looping is the problem

anyway as I said, I managed to carry out my stuff without using this, but if someone can figure out how to do the macro thingie I would be thankfull. I heard something that boost's preprocessor library can do that. didn't get to try it out : http://boost.org/libs/preprocessor/doc/ref/repeat.html.

cheers

Dave Sinkula commented: Boost never ceases to continue to amaze me. +13