Create a Main file

This is a discussion on Create a Main file within the C Programming forums, part of the General Programming Boards category; Hi, i am new to C language. Yesterday was my first day. I have to small programs. One that converts ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    1

    Create a Main file

    Hi, i am new to C language. Yesterday was my first day.
    I have to small programs. One that converts Fahrenheit to celsius in 20 degree increments and one that does it in 15 degree increments. they work fine but i was playing around with it and i wanted to make a Main file that calls both of them and displays the results.
    here is how my files look.
    Code:
    #include <stdio.h>
    
    /* convert Fahrenheit to celcius in steps of 20*/
    
    int steps = 20;		//increment steps
    Code:
    #include <stdio.h>
    
    /* convert Fahrenheit to celcius in steps of 15*/
    
    int steps = 15;		//increment steps
    this is the main.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <f_to_c.h>
    #include <f_to_c2.h>
    
    int fahr;
    int cels;
    int min = 0;		
    int max = 300;
    
    
    
    main() {
        fahr = min;
    
        while(fahr <= max){
    	cels = 5 * (fahr - 32) /9;
    	printf("%d\t%d\n", fahr, cels);
    	fahr = fahr + steps;    //increment fahrenheit by 20 degrees
    	}
    
    }
    when i run this, i get some error messages.
    Main.c:10:20: f_to_c.h: No such file or directory
    Main.c:11:21: f_to_c2.h: No such file or directory
    Main.c:26: error: `steps' undeclared (first use in this function)
    Main.c:26: error: (Each undeclared identifier is reported only once
    Main.c:26: error: for each function it appears in.)

    thank you in advance

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287
    I suppose that f_to_c.h and f_to_c2.h are placed on the same main.c file's folder. To include them you should specify the path (relative or absolute) to the files instead the realtive path to the compiler include's folder (or maybe you can configure you compiler to have also a look at you folder as it was part of the include folder):

    Code:
    //#include <f_to_c.h>
    #include "f_to_c.h"
    Note: since the main code have 'stdio.h' included, you don't need to include it on the auxiliar headers (or since you have included 'stdio.h' in your aux headers, you don't need to declare in the main code).

    Hope that helps
    Niara

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You'll just need one file, and have just one int main() function. That function should call your two other functions:

    Code:
    #include <stdio.h>
    
    //I doubt that you should keep all these, as globals, but for now, ok
    int fahr;
    int cels;
    int min = 0;		
    int max = 300;
    
    void FtoCby20(void);  //the functions definitions or prototypes
    void FtoCby15(void);
    
    int main(void)
       {
       int gar;
       FtoCby20();
       FtoCby15();
        
       printf("\n\n\t         Program Complete Press Enter When Ready ");
       gar = getchar(); gar++;  //holds the console window open, and stops warnings
       return 0;   //normal program termination has occurred 
       }
    
    void FtoCby20(void)
       {
       //add your code for this function, here
       }
    
    etc.
    Hope that helps.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  3. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  4. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  5. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21