Lab 1 Getting Started. Creating a C program Lab 1 : Getting Started Login information User name:...

Post on 21-Dec-2015

216 views 0 download

Tags:

Transcript of Lab 1 Getting Started. Creating a C program Lab 1 : Getting Started Login information User name:...

Lab 1

Getting Started

Creating a C program

Creating a C program

Creating a C program

Lab 1 : Getting Started

Login information User name: ge-208 Password: 111 Domain: ENG_MANAR

Starting the compiler Go to Start > Program Files >

Microsoft Visual Studio 6.0 > Microsoft Visual C++ 6.0

Writing a C program

Choose File > New Go to Files tab, then

choose Text File Type lab1daytime.c

in the filename field Choose C:\Documents

and Settings\ge-208\ in the save file location field.

General C Program

#include <stdio.h>

void main(void){

}

Write program hereWrite program here

preprocessor directive

primary function (main)

printf() Instruction

printf(printf("format_string""format_string", , argument_listargument_list));;

Prints what is written between the quotation marks on screen

Escape sequences are used to control output formatting

Escape Sequences

\a Alert/bell \b Backspace \n New line \r Carriage

return \t Tab

printf() Example

printf("This is line1\n");printf("This");printf(" is ");printf(“line2\nline3\n");

This is line1This is line2line3

Comments

Long comments can be inserted in a C program by placing them between /* */Example: /* This is a long comment in C-

programming */

Short comments in the same line can be written after //Example: printf(“\n"); //insert new line

Compilation Errors

If there are any errors in your program, the compiler will indicate the line number of the error along with an explanation.

See the bottom window to check the compiler’s output!!

/* Write your name, student number and comments here */#include <stdio.h>Void main(void){ Printf(“Welcome to”);Printf(“GE 208 Lab!\n”); Printf(“This line should give a beep!\a\n”); Printf(“This\tline\tis tabbed\n”); Printf(“This” “is” “another” “printf\n”); Printf(“One\”); Printf(“line\n”);Printf(“This should not appear\r where did the text go?\n”);Printf(“Where is the ‘C’ in ABC\b?\n”);Printf(“If you want to print \\, \\n, \” or %% on the screen\n”);}

Examples