Presentation is loading. Please wait.

Presentation is loading. Please wait.

EECE.2160 ECE Application Programming

Similar presentations


Presentation on theme: "EECE.2160 ECE Application Programming"— Presentation transcript:

1 EECE.2160 ECE Application Programming
Instructors: Dr. Michael Geiger & Dr. Lin Li Spring 2019 Lecture 2: Basic C program structure IDE demos

2 ECE Application Programming: Lecture 2
Lecture outline Announcements/reminders Chapter 1 exercises due Monday, 1/28 Textbook exercises always due 3 days after related lecture—check ”Assignments” tab regularly!!! Program 1 due Wednesday, 1/30 10 points: register for access to the course textbook 10 points: introduce yourself to your instructor 30 points: complete simple C program Today’s lecture Basic C program structure Comments IDE demo 4/23/2019 ECE Application Programming: Lecture 2

3 Review: Basic C program structure
#include <stdio.h> int main() { printf("Hello World!\n"); return 0; } Preprocessor directives #include: typically used to specify library files <stdio.h> is built-in standard input/output library Main function Starts with: int main() or void main() Enclosed in block: specified by { } Ends with return 0; Indicates successful completion 4/23/2019 ECE Application Programming: Lecture 2

4 Review: Basic C program structure
#include <stdio.h> int main() { printf("Hello World!\n"); return 0; } Basic output Call printf(<string>); <string> can be replaced by characters enclosed in double quotes May include escape sequence, e.g. \n (new line) 4/23/2019 ECE Application Programming: Lecture 2

5 Variation #1 of first program
What does this program print? #include <stdio.h> int main() { printf("Hello"); printf("there"); printf("World!"); return 0; } Output: HellothereWorld! No newlines  all one line of output No spaces  words printed next to one another 4/23/2019 ECE Application Programming: Lecture 2

6 Variation #2 of first program
What does this program print? #include <stdio.h> int main() { printf("Hello\n"); printf("there\n"); printf("World!\n"); return 0; } Output: Hello there World! Each newline moves cursor to next line 4/23/2019 ECE Application Programming: Lecture 2

7 Variation #3 of first program
What does this program print? #include <stdio.h> int main() { printf("Hello\nthere\nWorld!\n"); return 0; } Output: Hello there World! Works the same as variation #2 One printf() call can produce multiple output lines Proper style: one printf() call per output line unless lines are short 4/23/2019 ECE Application Programming: Lecture 2

8 Variation #4 of first program
#include <stdio.h> int main(){printf ("Hello\nthere\nWorld!\n");return 0;} Compiler doesn’t care about white space #include must be on its own line Compiler figures out start/end of blocks, statements using specific symbols Curly braces { } for block Semicolon ; for end of statement Works the same as variations #2 & #3 … … but looks much worse 4/23/2019 ECE Application Programming: Lecture 2

9 ECE Application Programming: Lecture 2
Code readability Readability wouldn’t matter if: Entire code project written by one person All code was in same file Same person is the only one to use the code Code was used only for a short period of time More typically: Projects are split—multiple programmers and files Code usually reused Multiple users Used/adapted (hopefully) over long period of time You may reuse code ... but forget what you originally wrote! Bottom line: code needs to be readable 4/23/2019 ECE Application Programming: Lecture 2

10 ECE Application Programming: Lecture 2
Comments C allows you to add comments to your code Single line comments: start with // Multi-line comments: start with /* end with */ Typical uses Multi-line comment at start of program with Author’s name (& other info if appropriate) Date started/modified Description of overall file functionality For individual code sections Comment for major section of code performing single function Comment for single line of code if that line alone is important Comments should be informative Takes some time to learn what should be commented 4/23/2019 ECE Application Programming: Lecture 2

11 ECE Application Programming: Lecture 2
Comment example /* EECE.2160: ECE Application Programming 4/23/2019 hello.c: Intro program to demonstrate basic C program structure and output */ #include <stdio.h> // Main program: prints basic string and exits int main() { printf("Hello World!\n"); // Comment return 0; } 4/23/2019 ECE Application Programming: Lecture 2

12 ECE Application Programming: Lecture 2
Assignment #1 Basic assignment to ensure you can write, run, and submit programs Write a short program that prints (each item on its own line): The name of the class The current semester The days on which lectures meet The instructors’ names For this assignment, spacing matters!!! 4/23/2019 ECE Application Programming: Lecture 2

13 ECE Application Programming: Lecture 2
IDE demos zyBooks IDE demo (Section 1.11 of the text) Basics of writing and compiling code Develop mode vs. submit mode Dealing with errors Compiler errors Incorrect output Test cases Visual Studio demo Setting up a project Building and running a project Getting project to pause at the end 4/23/2019 ECE Application Programming: Lecture 2

14 ECE Application Programming: Lecture 2
Final notes Next time Data types Variables Reminders Chapter 1 exercises due Monday, 1/28 Textbook exercises always due 3 days after related lecture—check ”Assignments” tab regularly!!! Program 1 due Wednesday, 1/30 10 points: register for access to the course textbook 10 points: introduce yourself to your instructor 30 points: complete simple C program 4/23/2019 ECE Application Programming: Lecture 2


Download ppt "EECE.2160 ECE Application Programming"

Similar presentations


Ads by Google