Does anyone knows how to read a data from the other file?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • micmicmic
    New Member
    • Nov 2009
    • 8

    Does anyone knows how to read a data from the other file?

    I can't link to the other file called A1.c, A2.c and A3.c respectively. Does anyone knows how to link to the other .c file from the following .c file?
    Code:
    #include<stdio.h>
    
    int main()
    {
        int choice;
     printf("             Main Menu\n");
     printf("             =========\n\n");
     printf("1.Simple Editor with Speed Calculation\n");
     printf("2.Simple Spell Checking\n");
     printf("3.Find & Replace\n");
     printf("4.Quit\n\n");
     
             do
            { 
             printf("Please enter your choice: ");
             scanf("%d",&choice); 
            }
            while(choice<1 || choice>4); 
            
             if(choice==1)
            {
             fopen("A1.c","r"); 
            }  
            else if(choice==2)
            {
             fopen("A2.c","r");
             }
            else if(choice==3)  
            {
             fopen("A3.c","r");
             }
            else if(choice==4)
            {
             printf("Welcome to come next time.");
             exit(1);
            }
            
     system("PAUSE");
     return 0;   
    }
    Last edited by Banfa; Nov 27 '09, 03:35 PM. Reason: Added [Code] ... [/code] tags
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    If you are trying to execute the C/C++ code written in Ax.c file based on user's choice, it's not done that way. You need to compile them and link resulting object files according to your compiler's documentation.

    Comment

    • micmicmic
      New Member
      • Nov 2009
      • 8

      #3
      But my one just use C, not Visual C/C++...What's the comand of it? I am a new guy for using C language...So I don't know what the command code is for this case.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        You need a makefile or you can identify these other files on the OS command line.

        The format of that line shouloe be in yhour compiler documentation.

        Are you using Visual C++?

        If so, just add these files to your project along with tile file containing main and click on build.

        Comment

        • micmicmic
          New Member
          • Nov 2009
          • 8

          #5
          I am sorry, I use C not visual C, C++

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            What compiler are you using then?

            Comment

            • micmicmic
              New Member
              • Nov 2009
              • 8

              #7
              Actually, I am only using Notepad...Then how can I link them?

              Comment

              • micmicmic
                New Member
                • Nov 2009
                • 8

                #8
                Can anyone give me an example?

                Comment

                • newb16
                  Contributor
                  • Jul 2008
                  • 687

                  #9
                  You can't run C or (C++ if that matters) program without compiler. ( i.e. make and run executable having source code). Use of notepad hints that you use windows - get mingw compiler if you have no compiler yet or tell us what compiler do you have.

                  Comment

                  • micmicmic
                    New Member
                    • Nov 2009
                    • 8

                    #10
                    I have DEV C++... but I seldom use it...Could you give me an example to link the .c files to .h file?

                    Comment

                    • newb16
                      Contributor
                      • Jul 2008
                      • 687

                      #11
                      If dev c++ uses gcc as a compiler, you may try
                      g++.exe main.cpp a1.cpp a2.cpp a3.cpp
                      It willl compile them and link obj files.

                      Comment

                      • micmicmic
                        New Member
                        • Nov 2009
                        • 8

                        #12
                        But I should open us C project...not C++...what should I include in the .h file to link the other C files within the same project?

                        Comment

                        • weaknessforcats
                          Recognized Expert Expert
                          • Mar 2007
                          • 9214

                          #13
                          You are asking fundamental questions whose answers are in any book on C or C++. I recommend the C++ Primer Plus 5th Edition by Stephen Prata.

                          There's also Google and Wikipedia.

                          We are available to assist getting your through specific problems but we are not set up to act as tutors.

                          Comment

                          Working...