D
dutchgoldtony
Hi, just need a bit of help!
I know this is a simple question but it's wrecking my head and I end up
just staring at the screen for ages...
I have a multi-source program -myProg1.cpp
-myProg2.cpp
-foo.h
All that happens is that myProg1 passes an int to myProg2 which uses
the int to dynamically allocate memory for an array using malloc()
I've done this before with no problem but not today!!!
Here's the code:
/* myprog1.cpp */
#include <stdio.h>
#include "foo.h"
int maxDepth;
void main(void)
{
int prenum;
printf("\nEnter the size of the word\n");
scanf("%d",&prenum);
maxDepth = prenum + 3;
myfunction();
}
/* myprog2.cpp */
#include <stdio.h>
#include <stdlib.h>
extern int maxDepth;
int * raw;
void myfunction(void) {
int i;
raw = (int)malloc(maxDepth * sizeof(int)); /*Error points to this
line*/
for(i=0;i<4;i++){
raw = i*i;
printf("%d/n",raw);
}
free(raw);
}
/* foo.h */
void myfunction(void);
I keep on getting the following error:
f:\project\test2\encoder.cpp(18) : error C2440: '=' : cannot convert
from 'int' to 'int *'
Conversion from integral type to pointer type requires
reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
I appreciate any help,
Tony
I know this is a simple question but it's wrecking my head and I end up
just staring at the screen for ages...
I have a multi-source program -myProg1.cpp
-myProg2.cpp
-foo.h
All that happens is that myProg1 passes an int to myProg2 which uses
the int to dynamically allocate memory for an array using malloc()
I've done this before with no problem but not today!!!
Here's the code:
/* myprog1.cpp */
#include <stdio.h>
#include "foo.h"
int maxDepth;
void main(void)
{
int prenum;
printf("\nEnter the size of the word\n");
scanf("%d",&prenum);
maxDepth = prenum + 3;
myfunction();
}
/* myprog2.cpp */
#include <stdio.h>
#include <stdlib.h>
extern int maxDepth;
int * raw;
void myfunction(void) {
int i;
raw = (int)malloc(maxDepth * sizeof(int)); /*Error points to this
line*/
for(i=0;i<4;i++){
raw = i*i;
printf("%d/n",raw);
}
free(raw);
}
/* foo.h */
void myfunction(void);
I keep on getting the following error:
f:\project\test2\encoder.cpp(18) : error C2440: '=' : cannot convert
from 'int' to 'int *'
Conversion from integral type to pointer type requires
reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
I appreciate any help,
Tony