|
-
June 3rd, 2006, 04:39 AM
#1
Error C2061 in header file!!
Im trying write a simple program to calculate the factorial of a number using VC++ 6,0 and i get an error which C2061 saying that factorial# is not an identifier and it couldn't be found and needs to be declared before being used????
heres the code:
#include <stdio.h>
#include <conio.h>
#include <D:\VC++\chapter3\factorial\factorial.h>
int number,factorial;
int main()
{
printf("enter the number\n");
scanf("%d",&number);
if (number = 0)
{
printf("the factorial is 1");
system("exit");
}
factorial = calc_fact(number);
printf("the factorial of %d is %d\n",number,factorial);
system("pause");
}
and heres the header file:
int calc_fact(int number)
{
int factorial3;
while(number != 0) do
number *= --number;
factorial3 = number;
return factorial3;
}
what changes do i have to make in the program and/or program settings to make this exceedingly simple program to work. and theres another thing i wanna know. If I include the file using the ".." after the #include then it agains gives me an error..thats a different Q but right now im bothered about my current program. And what header files shud be included for system functions?
-
June 3rd, 2006, 05:21 AM
#2
Re: Error C2061 in header file!!
Your #include is incorect
Code:
#include "D:\\VC++\\chapter3\\factorial\\factorial.h"
Now should work.
Please use code tags [code] [/code]
We would change the world, but God won't give us the sourcecode.. 
Undocumented futures are fun and useful....
_________
Gili
-
June 3rd, 2006, 05:48 AM
#3
Re: Error C2061 in header file!!
My recommandation is not to use absolute paths. You should add "D:\VC++\chapter3\factorial\" to Additional Include Directories, and simoky iclude the header:
Code:
#include "factorial.h"
-
June 3rd, 2006, 06:56 AM
#4
Re: Error C2061 in header file!!
Thanks a lot u guys for the quick reply. However I had to adopt this methodology as using it without absolute paths was leading to an error which mentioned that it couldn't find the header file itself.
I tried a lot of different methods and to be on the safe side i decided to include the absolute path.
In actuality i do understand that the compiler checks the project directory first to see if it can find the header file but it wasnt doing that in my case. Has it got something to do with the mode in which i am operating in i.e. debug mode or release mode??
Hope this would make it more easier for u guys to understand what exactly im facing here. The actual problem that I am facing is that the compiler doesn't recognize the identifier factorial3. Heres what it says:
Compiling...
factorial1.c
D:\\VC++\\chapter3\\factorial\\factorial.h(8) : error C2061: syntax error : identifier 'factorial3'
Error executing cl.exe.
Best Regards,
Aijaz.
Last edited by aijazbaig1; June 3rd, 2006 at 06:59 AM.
Reason: Forgot to mention something imp.
-
June 3rd, 2006, 09:37 AM
#5
Re: Error C2061 in header file!!
Well, for that you have to show the content of file factorial.h.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|