hello guyz iv got problem with void pointers i cant work this out !
i'm trying to read from a binary file using a struct and pass this struct arrays to class object and push them to stack and display them on screen while poping them out !
but the problem that i have a strict code and i cant change it which is a void pointers for push and pop
i know the whole code is messy coz i'm using C but i'm trying ma best to learn c++
anyways here is my code i'm using vc++
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
using namespace std;
enum sex {male, female};
typedef struct data {
char fname[30];
sex MF;
int age;
double wit;
}records;
records student[10];
class s {
private:
int top;
int current;
void *layer[100];
public:
stack(void)
{
top=0; //dont worry about the top and the current its //only for push and pop error checking
current=0;
}
int push(void *myobject) //my whole problem is in here because i cant change the int or even the void and the same for the pop()
{
records * layer= (records *) myobject;
}
void* pop(void)
{
return layer[100];
}
};
int _tmain(int argc, _TCHAR* argv[])
{
stack name[10],age[10],weight[10];
FILE *fp;
if (( fp = fopen ( "datab.data", "rb" ) ) == NULL )
{
printf ( "Cannot open file\n" );
exit ( 1 );
}
fread(student,200,3,fp);
name[1].push(student[0].fname); // so here i create stack
//called name wel it was a test just to push one records to stack
//well the push method was successful but i couldnt pop them out i got totaly different characters
name[1].pop();
/* for(int i=0; i<10; i++)
{
printf("%s %s %d %2.2f\n", student[i].fname,student[i].MF == 0 ? "Male" : "Female",student[i].age,student[i].wit);
}*/
fclose ( fp );
return 0;
}
i'll appreciate any help and once again i know its totally messy code for using C but still trying ma best to hit C++