Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C For Dummies 2nd Ed 2004.pdf
Скачиваний:
52
Добавлен:
17.08.2013
Размер:
8.34 Mб
Скачать

Appendix A

The Stuff You Need to Know before You Read All the Other Stuff in This Book

In This Appendix

Configuring your computer as a programming workstation

Selecting a compiler

Choosing an editor

Creating programs

You need a few things before C programming is possible on your computer. The purpose of this appendix is to outline what you need and how to use

it in order to work with the sample programs in this book. It’s not that hard, but it may be something you’re not used to, so pay attention!

Setting Things Up

You need two things to program in C on your computer:

A compiler

A place to put your programs

For Linux, Unix, and the Mac OS X operating system, your C language compiler is already included; it comes with the operating system. For Windows and older Mac systems, you must obtain a compiler. That’s not as difficult as it sounds.

360 C For Dummies, 2nd Edition

The C language compiler

Thanks to the C language’s popularity, many compilers are available for you to use with this book. I do, however, recommend the following:

Windows: If you’re using Windows, I recommend that you get a GCC-compatible C compiler. A list of compilers is provided on this book’s Web page, at www. c-for-dummies.com.

For this book, I used the MinGW compiler, which comes with the Dev-C++

IDE (Integrated Development Environment). It’s free and available from

www.bloodshed.net.

Whichever compiler you use, note its location on your PC’s hard drive. You have to use this location to create a batch file or modify your system’s path so that you can access the compiler from any folder in your disk system.

More on that later.

Other compilers are out there, including the best-selling Microsoft Visual C++ (MSVC). If you have MSVC, fine; you should be okay with running the programs in this book. Note, however, that I’m not familiar with the current version of MSVC and don’t refer to it in this book, nor can I answer questions about it via e-mail. If you don’t have MSVC, you have no reason to buy it.

Plenty of free, shareware, and open-source C compilers are available on the Internet.

If you have other books on the C language, check in the back of the book

for a free compiler.

Any GCCor GNU-compatible C compiler works best with this book.

Linux, FreeBSD, or Mac OS X: If you’re using any of these variations of Unix, you should already have the GCC compiler installed and ready to use. To confirm, open a terminal window and type the following line at the command prompt:

gcc -v

The version number of GCC and other information is displayed on the screen. If you get a Command not found error, GCC isn’t installed; you have to update your operating system to include GCC as well as all the C programming librar­ ies and other materials. (You can generally do that through your operating system’s setup or configuration program; it doesn’t typically require that the entire operating system be reinstalled.)

Appendix A: The Stuff You Need to Know before You Read All the Other Stuff 361

Unix: If you have a “real” version of Unix, the command is cc and not gcc. In fact, you may notice that cc even works on other Unix-like operating systems, where the cc command is often linked to the GCC compiler, for compatibility’s sake.

Mac (before OS X): Older versions of the Mac lack a built-in C language com­ piler. I recommend the Code Warrior compiler, though you should also check the Apple Web site to see whether any other (free) compilers are available: http://developer.apple.com/.

The place to put your stuff

When you learn to program, you create scads of files. These files include the original-text source code files, the final program files, and perhaps even object code files, depending on the compiler. Obviously, you want to keep those files organized and separate from your regular junk.

For this book, I recommend creating a prog folder or directory. Create this folder off your main folder — the $HOME folder in Unix or the My Documents folder in Windows. The prog folder is designed to hold all your programming projects.

Beneath prog, you should put the c folder, for all your C language program­ ming projects.

Finally, create a learn folder, in which you put all the projects for this book. The rest of this appendix provides specific examples.

Windows. To create a folder for your C language projects, follow these steps:

1.Open the My Documents icon on the desktop.

2.Choose File New Folder to create a new folder and then name the folder prog.

3.Open the prog folder.

4.Choose File New Folder to create a new folder, and then name it c.

5.Open the c folder.

6.Create a folder inside the c folder, and name that folder learn.

7.Close the c folder window.

362 C For Dummies, 2nd Edition

The learn folder is where you place all the files created in this book.

Linux, FreeBSD, Mac OS X, or Unix: To create a folder for your C program­ ming projects, obey these steps:

1.If you’re using a graphical shell, open a terminal window. You need to get at the command prompt.

The terminal window should open into your account’s home directory. If you aren’t in your home directory, type the cd command to return there.

Ensure that you’re not logged in as the root account; creating programs as the root user is a security risk.

2. Create the prog/c/learn directory branch:

mkdir -p prog/c/learn

The -p switch directs mkdir to create all the subdirectories that are speci­ fied; it’s the same as issuing three separate mkdir commands at once. With one command, you have created the prog directory, the c subdirec­ tory, and, finally, the learn subdirectory. Ta-da.

You use the learn folder for storing all the source code and program files created in this book.

Mac (before OS X). Alas, the old Mac operating system lacked a “home folder” for all your stuff. If you have such a folder, use it as a base to create the subfolders in the following steps. Otherwise, you can create these folders right on the desktop for handy access:

1.Press Ú+N to create a new folder.

2.Name that folder prog, for “programming.”

3.Open the prog folder.

4.Press Ú+N to create a subfolder inside the prog folder.

5.Name that folder c.

6.Open the c folder.

7.Press Ú+N to create a subfolder inside the c folder.

8.Name that subfolder learn.

9. Close all the open windows you just created.

When using your compiler, remember to save all your files in the learn folder.