Sams Teach Yourself C in 24 Hours

Read Online Sams Teach Yourself C in 24 Hours by Tony. Zhang - Free Book Online

Book: Sams Teach Yourself C in 24 Hours by Tony. Zhang Read Free Book Online
Authors: Tony. Zhang
Ads: Link
to use the C compiler that is bundled with the Microsoft’s Visual C++ package in this section. If you need to learn more details on how to install Visual C++, please follow the instructions that come with the compiler.
    Now I assume you’ve installed a copy of Visual C++ 5.0 on your computer. To start the compiler, you can click the Start button from your Windows 95 (or 98 or NT), and choose: Programs, Microsoft Visual C++ 5.0, Microsoft Visual C++ 5.0. Or, you can simply run the application file MSDEV.EXE directly from the directory (folder) where you installed the Visual C++ package. Figure 1.3 shows an example of the integrated development environment (IDE) from Visual C++ 5.0.
    FIGURE 1.3
    An example of the IDE
    from Visual C++ ver-
    sion 5.0.
    Then, you can open a new file within the IDE by clicking the New File button on the far left side of the toolbar, and type the following text in the space of the new file:
    #include
    main()
    {
    printf (“Howdy, neighbor! This is my first C program.\n”);
    return 0;
    }

    03 067231861x CH01 4.10.2000 10:59 AM Page 19
    Taking the First Step
    19
    Figure 1.4 shows the IDE with the text you just typed in. Don’t worry about the meaning of the text. In the next chapter, “Your First C Program,” will explain it to you.
    1
    FIGURE 1.4
    Writing code in the
    Visual C++ 5.0 IDE.
    Then, you need to save the text as a file. Let’s call the file MyFirstProgram.c. It is also a good idea to create a new directory on your hard drive to store your programming projects, and save the new file there. First, click the Save button on the toolbar. In the Save As dialog box, click the New Folder button and type in a name for your programming folder. Then double-click that folder to open it, type MyFirstProgram.c in the File Name box, and click Save. Note that the extension .c is used to indicate that the file you just saved is a C program file.
    Now, you need to click the Build menu and choose the Compile MyFirstProgram.c option. By doing so, you ask the compiler to compile the text you just typed in and saved (see Figure 1.5). At this point, Visual C++ may prompt you to create a new workspace; just click Yes and this will be done automatically. There should be no errors or warnings in the output window after the compiler is run.
    Then, click the Build menu again, and this time, choose the Build MyFirstProgram.exe option which will eventually produce an executable file called MyFirstProgram.exe.
    Figure 1.6 shows that there are no errors or warnings after MyFirstProgram.exe is built.

    03 067231861x CH01 4.10.2000 10:59 AM Page 20
    20
    Hour 1
    FIGURE 1.5
    Compiling a C pro-
    gram using the IDE.
    FIGURE 1.6
    Creating a program
    executable file.
    You are now ready to run the executable file, MyFirstProgram.exe, that you just compiled. You can run it from the menu path: Build, Execute MyFirstProgram.exe. Because the executable file is a console mode application, a DOS prompt window will show up when the executable file is running (see Figure 1.7).

    03 067231861x CH01 4.10.2000 10:59 AM Page 21
    Taking the First Step
    21
    FIGURE 1.7
    Running a C program.
    1
    You can tell that the first line in the DOS prompt window shown in Figure 1.7 is the exact line you just typed: “Howdy neighbor! This is my first C program.” This is indeed your first C program output! (Note that the second line shown in the DOS prompt is just a built-in reminder from the DOS prompt window.)
    Okay. I just demonstrated how to use Visual C++ compiler to write and compile a C program, and how to make the program executable. For more details, you need to read books such as Teach Yourself Visual C++ 5 in 21 Days that focus on teaching you how to use Visual C++ compiler.
    Using Borland’s Compiler
    In this section, I’m going to show you how to use the C compiler that is bundled with Borland’s C++ package. The procedure of the section is quite similar as the one of the previous section. If you need to learn more

Similar Books

The Ramblers

Aidan Donnelley Rowley

Oppressed

Kira Saito

Missing From Home

Mary Burchell

My Lord's Lady

Sherrill Bodine

Can't Touch This

Marley Gibson