CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2006
    Location
    Sweden
    Posts
    19

    Question 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?

  2. #2
    Join Date
    Mar 2005
    Location
    Romania,Cluj-Napoca
    Posts
    1,073

    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

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    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"
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Jun 2006
    Location
    Sweden
    Posts
    19

    Post 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.

  5. #5
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Error C2061 in header file!!

    Well, for that you have to show the content of file factorial.h.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured