W
W. Van Hooste
Just starting with C, can somebody explain why this does not work or
point me in the right direction? I wrote some tools and did some
coding but cant seem to get this one. I DID declare my FILE *fp! and
still get...
isource2.c: In function `getval':
isource2.c:5: `FILE' undeclared (first use in this function)
Here is my Example project:
$ls
Makefile file1 isource2.c isource2.h source1.c
$cat source1.c
#include <stdio.h>
#include "isource2.h"
main()
{
int val;
val = getval();
printf("in main: %d\n", val);
}
$cat isource2.c
int
getval(void)
{
FILE *fp;
int val;
fp = fopen("file1", "r");
fscanf(fp, "%u", &val);
printf("in getval: %d\n", val);
fclose(fp);
return (int) (val);
};
$cat isource2.h
int getval(void);
$cat file1
50
$cat Makefile
testtool: source1.o isource2.o
gcc -o source1 source1.o isource2.o
source1.o: source1.c isource2.h
gcc -g -c source1.c
isource2.o: isource2.c
gcc -g -c isource2.c
$make
gcc -g -c source1.c
gcc -g -c isource2.c
isource2.c: In function `getval':
isource2.c:5: `FILE' undeclared (first use in this function)
isource2.c:5: (Each undeclared identifier is reported only once
isource2.c:5: for each function it appears in.)
isource2.c:5: `fp' undeclared (first use in this function)
make: *** [isource2.o] Error 1
Don't understand, please explain - this should work, according to me
it's straigt forward! Isn't it????
Greetz..
point me in the right direction? I wrote some tools and did some
coding but cant seem to get this one. I DID declare my FILE *fp! and
still get...
isource2.c: In function `getval':
isource2.c:5: `FILE' undeclared (first use in this function)
Here is my Example project:
$ls
Makefile file1 isource2.c isource2.h source1.c
$cat source1.c
#include <stdio.h>
#include "isource2.h"
main()
{
int val;
val = getval();
printf("in main: %d\n", val);
}
$cat isource2.c
int
getval(void)
{
FILE *fp;
int val;
fp = fopen("file1", "r");
fscanf(fp, "%u", &val);
printf("in getval: %d\n", val);
fclose(fp);
return (int) (val);
};
$cat isource2.h
int getval(void);
$cat file1
50
$cat Makefile
testtool: source1.o isource2.o
gcc -o source1 source1.o isource2.o
source1.o: source1.c isource2.h
gcc -g -c source1.c
isource2.o: isource2.c
gcc -g -c isource2.c
$make
gcc -g -c source1.c
gcc -g -c isource2.c
isource2.c: In function `getval':
isource2.c:5: `FILE' undeclared (first use in this function)
isource2.c:5: (Each undeclared identifier is reported only once
isource2.c:5: for each function it appears in.)
isource2.c:5: `fp' undeclared (first use in this function)
make: *** [isource2.o] Error 1
Don't understand, please explain - this should work, according to me
it's straigt forward! Isn't it????
Greetz..