1 / 25

EE312 Lesson 2: Operating Systems/ C language

EE312 Lesson 2: Operating Systems/ C language. Operating System Topics. Operating System Interfacing Services Provided File Systems Files Directories Paths Methods of Interaction GUI Shell. Operating System Function. Users / Applications Operating System Hardware. Services.

menora
Download Presentation

EE312 Lesson 2: Operating Systems/ C language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. EE312 Lesson 2:Operating Systems/ C language

  2. Operating System Topics • Operating System Interfacing • Services Provided • File Systems • Files • Directories • Paths • Methods of Interaction • GUI • Shell

  3. Operating System Function • Users / Applications • Operating System • Hardware

  4. Services • File Operations • Network Connections • User Accounts / Permissions • Processes / Programs

  5. File System Hierarchy • Files • Documents • Programs • OS • Folders/Directories • Containers for Files and Subdirectories • Paths • Absolute • Relative

  6. User Interaction • GUI • Graphical User Interface • CLI • Command Line Interface (Shell)

  7. CLI commands for Windows and Unix ands

  8. C Language Topics • Computer Languages • Program Lifecycle • Source Code [C] • Compilation • Binary File (Executable) • Execution in RAM • Debugging • Program structure • Stamp, variables, syntax, semicolon, comments • Simple input and output • Program errors

  9. Topics • Program Output printf() • Format Strings • % Format Identifier • Program Input • scanf() • Typecasting

  10. Machine Language Program- Object Code

  11. Assembly Language Program- Low LevelInstruction Code Using assembly language, if we wanted to, say, add, then instead of using the code 0100011 which is machine language code, we would instead use the corresponding assembly language instruction ADD. Program 1 above might appear as Program 2 below, written in assembly language. Program 2 LOAD A MUL B ADD C STORE D

  12. C Language- Source code- High level

  13. Program cycle

  14. Program Structure • So, our program layout can be further refined: • #include <stdio.h> • int main( ) • { • variable declarations • statement 1 • statement 2 • (etc., etc.) • statement n • return 0; • }

  15. Variables

  16. Variable Examples

  17. Assignment

  18. Simple Output

  19. Printf Examples

  20. Simple input • For example, to read an item from the keyboard and place the value into a variable named year_number of type int, we use: • scanf(“%d” , &year_number); • It is a very common error to omit the &. • B. Prompting the user. Before reading something from the keyboard, it is always a good idea to prompt the user to enter the value. • Example • What is the output produced by this complete C program: • #include<stdio.h> • int main() • { • int year_number; • printf("Enter the year: ") ; • scanf("%d" , &year_number); • printf("\nThe year is %d \n" , year_number); • return 0; • The ampersand that precedes the variable year_number is the address operator. We’ll talk more about this later. For now, just remember that with the scanf statement you want to ensure you include an ampersand before each variable name of type int, float and char.

  21. Prompting for input • C. Entering multiple values with one scanf. You can enter multiple values using a single scanf statement. This is illustrated in the example below. • Example • What is the output produced by this complete C program: • #include<stdio.h> • int main() • { • int year, month; • printf("Enter the year and the month (1-12): ") ; • scanf("%d %d" , &year , &month); • printf("\nIt is now %d / %d \n" , month , year); • } • Solution:

  22. Errors • V. Program Errors • A program error is termed a bug. The process of finding and eliminating program errors is called debugging. There are three different types of program errors. • Syntax errors (also called compile-time errors or compilation errors). These are violations of the C grammar rules. These errors are caught by the compiler. • Run-time errors (also called execution-time errors). These are errors that are detected as the program is running. These errors usually entail an attempt to perform an illegal operation, and usually cause the program to crash. • Logic errors – the hardest to find! The program is grammatically correct and executes without errors, but does not do what we want it to do. As an example, suppose we calculate the average of two float values a and b and assign the result to a float variable named average by using: • average = a + b /2.0 ; • Since C evaluates division before addition, the statement above will be understood by the C compiler as: • average = a + (b /2.0) ; • which is, of course, not what we intend! • To avoid logic errors, you should “trace-through” your program on paper to make sure the logic is correct. When you trace through the program, you should consider various input possibilities. • Statistics show that the amount of a programmer’s time that is spent on debugging is (pick one): • 10% 25% 33% >50%

More Related