Intro Programming
Intro Programming
Applications
Hello World! in C using DOS Window Command Prompt
Turgay Korkmaz
Office: SB 4.01.13 Phone: (210) 458-7346 Fax: (210) 458-4437 e-mail: korkmaz@cs.utsa.edu web: www.cs.utsa.edu/~korkmaz
Lecture = 1;
Install Microsoft Visual C++ Express 2008 (free) http://www.microsoft.com/express/vc/ Write a Hello World! Program Compile and Execute it in Windows In class, we will do this in a simple way using DOS Window Command Prompt
If you are interested in using IDE or Linux, yes you can! Ill give you instructions to start.
2
Start All Programs Microsoft Visual C++ Express 2008 Visual Studio Tools Visual Studio 2008 Command Prompt
3
cd C:\
hello Notepad window will appear and ask if you want to create the file. Click yes!
Inside DOS window, type Right-click mouse inside DOS window Select the Mark option Drag and highlight the results you want to print Hit Enter Move the cursor with the mouse to output.txt, which you have previously opened with Notepad Paste the text you have marked into output.txt Save it or Use Print of Notepad
7
Open Windows file manager and type Z:\myprog or C:\myprog into Address field
On C source file, Click Right Button and select Open With Notepad
8
Test HW
Modify your last program such that, after your name, it prints the names of your three favorite courses! Make sure the first one is CS 2073 Computer Programming with Engineering Applications Save it As test1.c, compile and execute it Copy/paste the output into output1.txt Submit test1.c and output1.txt via 9 WebCT(BB)
/* Another Exercise: Implement this program and execute it. What does it do? */ #include <stdio.h> #include <stdlib.h> int main( ) { double tC; /* temperature in Centigrade */ double tF; /* temperature in Fahrenheit */ /* * Prompt for centigrade temperature */ printf("What is the temperature in Centigrade? "); scanf("%lf", &tC); /* * Convert it to Fahrenheit */ tF = 9.0 * tC / 5.0 + 32.0; printf("%.2f in Centigrade is %.2f in Fahrenheit\n, tC, tF); } return 0; /* signal normal end of program */
10
To compile a C program under Windows, you can also use Microsoft Visual Studio or Microsoft Visual C++ 2008 Express IDE (integrated development environment), a software application that provides comprehensive facilities to computer programmers. An IDE consists of at least a source code editor, a compiler and a debugger etc. !! In class we will go with the simple DOS window approach to write and compile our programs !! But if you are interested in using IDE, then here are the directions. If you are not interested in IDE, SKIP this slide!
1. Select Start -> All Programs -> Microsoft Visual C++ 2008 Express Edition 2. Select File -> New -> Project from IDE menu 3. A dialog box will appear: Select Win32, Win32 Console Application, and name your project (e.g., HW1), click OK 4. Win32 Application Wizard will appear. Click Next, mark/select Empty Project, click Finish 5. Select Project -> Add new item from IDE menu 6. A dialog box will appear: Select C++ File, name your file (e.g., HW1.c), click Add 7. Type/edit your C program in HW1.c window and save it
11
Similar to DOS Window. If you plan to use Linux, I can give you more instructions. Just ASK. But, if you are not interested in Linux, SKIP this slide!
Type your program and save it (ctrl-o) Compile and execute your program
main212:> gcc hello.c o hello main212:> hello
12