Reputation: 85
I am trying to learn how to make a modular program. So what I want to do is read an array of integers. Main:
#include <stdio.h>
#include <stdlib.h>
#define NMAX 10
void read (int *n, int a[NMAX]);
int main()
{
int n, a[NMAX];
read(&n,a);
return 0;
}
Then I saved this file 'read.cpp':
#include <stdio.h>
#include <stdlib.h>
#define NMAX 10
void read (int *n, int a[NMAX])
{
int i;
printf("dati n:\n");
scanf("%d",n);
for (i=1;i<=*n;i++)
{
printf("a[%d]= ",i);
scanf("%d\n",&a[i]);
}
}
read.cpp compiles succesfully, but when I compile the main function I get the error "no reference to read".
Upvotes: 0
Views: 102
Reputation: 2853
Include read.cpp
when compiling.
g++ -o out main.cpp read.cpp
or
add #include "read.cpp"
in main program
Upvotes: 1