CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 11, SPRING 2013
|
|
- Britton Webb
- 7 years ago
- Views:
Transcription
1 CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 11, SPRING 2013
2 TOPICS TODAY C Input/Output Characters & Strings in C Structures in C Project 4
3 C INPUT/OUTPUT
4 stdin, stdout, stderr C opens three input/output devices automatically: stdin The standard input device, usually your keyboard stdout The standard output device, usually your monitor stderr The standard error device, usually your monitor Some C library I/O functions automatically use these devices Adapted from Dennis Frey CMSC 313 Fall 2011
5 Formatted Console Output printf( ) outputs formatted text to stdout Example: printf( format, arg1, arg2, ); int n = 3 ; printf ( Value = %d\n, n) ; format is a string containing conversion specifications literals to be printed Adapted from Dennis Frey CMSC 313 Fall 2011
6 printf( ) conversions Conversions specifications begin with % and end with a conversion character. Between the % and the conversion character MAY be, in order A minus sign specifying left-justification The minimum field width A period separating the field width and precision The precision that specifies Maximum characters for a string Number of digits after the decimal for a floating point Minimum number of digits for an integer An h for short or an l (letter ell) for long man printf for more documentation. Adapted from Dennis Frey CMSC 313 Fall 2011
7 Common printf( ) Conversions %d print integer as a decimal number (base 10) %u print integer as unsigned number %s print string %f print double as a floating point number %x print integer in hexadecimal (base 16) %c print integer as ASCII character %p print pointer in hexadecimal (implementation dependent) Adapted from Dennis Frey CMSC 313 Fall 2011
8 printf( ) Examples int anint = 5678; double adouble = 4.123; #define NAME Bob /* what is the output from each printf( ) */ printf ( %d is a large number\n, anint); printf ( %8d is a large number\n, anint); printf ( %-8d is a large number\n, anint); printf ( %10.2f is a double\n, adouble); printf( The sum of %d and %8.4f is %12.2f\n, anint, adouble, anint + adouble); printf ( Hello %s\n, NAME); Adapted from Dennis Frey CMSC 313 Fall 2011
9 Formatted Output Example Use field widths to align output in columns int i; for (i = 1 ; i < 5; i++) printf("%2d %10.6f %20.15f\n", i,sqrt(i),sqrt(i)); Adapted from Dennis Frey CMSC 313 Fall 2011
10 Keyboard Input scanf reads user input from stdin. Syntax for scanf( ) is similar to printf( ) scanf( format, arg1, arg2,... ) The format string similar structure to printf( ). The arguments must be addresses of the variables. Adapted from Dennis Frey CMSC 313 Fall 2011
11 scanf( ) format string The scanf( ) format string usually contains conversion specifications that tell scanf( ) how to interpret the next input field. An input field is a string of non-whitespace characters. The format string usually contains Blanks or tabs which are ignored Ordinary characters which are expected to match the next (nonwhitespace) character input by the user Conversion specifications usually consisting % character indicating the beginning of the conversion An optional h, l (ell) or L A conversion character which indicates how the input field is to be interpreted. Adapted from Dennis Frey CMSC 313 Fall 2011
12 Common scanf( ) conversions %d a decimal (integer) number %u an unsigned decimal (integer) number %x a hexadecimal number %f a floating point number with optional sign, decimal point, and exponent %s a string delimited by white space, NOT an entire line %c a single character (possibly a whitespace char) Adapted from Dennis Frey CMSC 313 Fall 2011
13 scanf( ) examples int age; double gpa; char initial; printf( input your middle initial: ); scanf ( %c, &initial ); printf( Input your age: ); scanf( %d, &age ); printf( input your gpa: ); scanf ( %lf, &gpa ); // note & Adapted from Dennis Frey CMSC 313 Fall 2011
14 Unix I/O redirection Redirect input (read from infile instead of keyboard): a.out < infile Redirect output (write to outfile instead of screen): a.out > outfile Redirect both: a.out < infile > outfile Redirect stdout and stderr to outfile a.out >& outfile Redirect stdout to outfile and stderr to errfile (a.out > outfile) >& errfile Adapted from Dennis Frey CMSC 313 Fall 2011
15 Text File I/O Use fprintf() and fscanf() functions instead of printf() and scanf(). Must open file before reading/writing: fopen() Must close file after all done: fclose() Use file handle to specify file. File handle returned by fopen(): FILE *myfile ; myfile = fopen ( bob.txt, r ) ; if (myfile == NULL) { } /* handle the error */ Adapted from Dennis Frey CMSC 313 Fall 2011
16 fopen( ) fopen( ) requires two parameters 1. The name of the text file to be opened 2. The text file open mode r w a open the file for reading only create the file for writing; delete existing file append; open or create the file for writing at the end r+ open the file for reading and writing w+ a+ create the file for reading & writing; deletes existing file open or create the file for reading or writing at the end Adapted from Dennis Frey CMSC 313 Fall 2011
17 fscanf.c #include <stdio.h> #include <stdlib.h> /* for exit */ int main ( ) { double x ; FILE *ifp ; /* try to open the file for reading, check if successful */ /* if it wasn't opened exit gracefully */ ifp = fopen("test_data.dat", "r") ; if (ifp == NULL) { printf ("Error opening test_data.dat\n"); exit (-1); } fscanf(ifp, "%lf", &x) ; /* read one double from the file */ fclose(ifp); /* close the file when finished */ /* check to see what you read */ printf("x = %.2f\n", x) ; return 0; } Adapted from Dennis Frey CMSC 313 Fall 2011
18 Detecting end-of-file with fscanf When reading an unknown number of data elements from a file using fscanf( ), we need a way to determine when the file has no more data to read, i.e, we have reached the end of file. Fortunately, the return value from fscanf( ) holds the key. fscanf( ) returns an integer which is the number of data elements read from the file. If end-of-file is detected the integer return value is the special value EOF Adapted from Dennis Frey CMSC 313 Fall 2011
19 EOF example code /* code snippet that reads an undetermined number of integer student ages from a file and prints them out as an example of detecting EOF */ FILE *infile; int age; infile = fopen( myfile, r ); if (infile == NULL) { printf ("Error opening myfile\n"); exit (-1); } while ( fscanf(infile, %d, &age ) = EOF ) { printf( %d\n, age ); } fclose( infile ); Adapted from Dennis Frey CMSC 313 Fall 2011
20 fprintf.c #include <stdio.h> #include <stdlib.h> /* exit */ int main ( ) { double pi = ; FILE *ofp ; /* try to open the file for writing, check if successful */ ofp = fopen("test.out", w") ; if (ofp == NULL) { printf ("Error opening test.out\n"); exit (-1); } /* write to the file using printf formats */ fprintf(ofp, Hello World\n ); fprintf(ofp, PI is defined as %6.5lf\n, pi); fclose(ofp); /* close the file when finished reading */ return 0; } Adapted from Dennis Frey CMSC 313 Fall 2011
21 CHARACTERS & STRINGS
22 char type C supports the char data type for storing a single character. char uses one byte of memory. char constants are enclosed in single quotes char mygrade = A ; char yourgrade =? ;
23 ASCII Character Chart
24 Special Characters Use \ for escape sequences. For example \n is the newline character \t is the tab character \ is the double quote (necessary since double quotes are used to enclose strings \ is the single quote (necessary since single quotes are used to enclose chars \\ is the backslash (necessary since \ now has special meaning \a is beep which is unprintable
25 Special Char Example Code What is the output from these statements? printf( \t\tmove over\n\nworld, here I come\n"); Move over World, here I come printf("i\ ve written \ Hello World\ \n\t many times\n\a ); I ve written Hello World many times <beep>
26 Character Library Functions int isdigit (int c); Determine if c is a decimal digit ( 0-9 ) int isxdigit(int c); Determines if c is a hexadecimal digit ( 0-9, a - f, or A - F ) int isalpha (int c); Determines if c is an alphabetic character ( a - z or A- Z ) int isspace (int c); Determines if c is a whitespace character (space, tab, etc) int isprint (int c); Determines if c is a printable character int tolower (int c); int toupper (int c); Returns c changed to lower- or upper-case respectively, if possible
27 Character Library Functions Include header file use character library functions: #include <ctype.h> Technically functions take an int parameter, not char. Return type is also int. 0 = False, not 0 = True. man ctype.h for more functions and complete documentation.
28 Character Input/Output Use %c in printf( )and fprintf( )to output a single character. char yourgrade = A ; printf( Your grade is %c\n, yourgrade); Input char(s) using %c with scanf( ) or fscanf( ) char grade, scores[3]; %c inputs the next character, which may be whitespace scanf( %c, &grade); %nc inputs the next n characters, which may include whitespace. scanf( %3c, scores); // note -- no & needed
29 Strings in C String = null terminated array of char. null = '\0' String constants in double quotes are null terminated. Strings do not "know" their own length. Initialization: char name4[ 20 ] = { B, o, b, b, y, \0 }; char name5[6] = Bobby ; // NOT assignment, needs 6 slots char name6[ ] = Bobby ;
30 String Output char name[ ] = Bobby Smith ; printf( My name is %s\n, name); // Right and left justify printf ( My favorite books are %12s and %12s\n, book1, book2); printf ( My favorite books are %-12s and %-12s\n, book1, book2);
31 Dangerous String Input char name[22]; printf( Enter your name: ); scanf( %s, name); Why is this dangerous? Long name will overwrite memory.
32 Safer String Input char name[ 22 ]; printf( Enter your name: ); scanf( %21s, name); // note 21, not 22, 1 byte for '\0'
33 C String Library C provides a library of string functions. To use the string functions, include <string.h>. Some of the more common functions are listed here on the next slides. To see all the string functions, type man string.h at the unix prompt.
34 C String Library (2) Must #include <string.h> strlen( const char string[ ] ) Returns length of string, not counting '\0' strcpy( char s1[ ], const char s2[ ] ) Copies s2 on top of s1. Must have enough space in s1 The order of the parameters mimics the assignment operator strcmp ( const char s1[ ], const char s2[ ] ) Returns < 0, 0, > 0 if s1 < s2, s1 == s2 or s1 > s2 lexigraphically strcat( char s1[ ], const char s2[ ]) Appends (concatenates) s2 to s1. Must have enough space in s1
35 C String Library (3) Some safer functions from the C string library: strncpy( char s1[ ], const char s2[ ], int n ) Copies at most n characters of s2 on top of s1. Does not null terminate s1 if length of s2 >= n The order of the parameters mimics the assignment operator strncmp ( const char s1[ ], const char s2[ ], int n ) Compares up to n characters of s1 with s2 Returns < 0, 0, > 0 if s1 < s2, s1 == s2 or s1 > s2 lexigraphically strncat( char s1[ ], const char s2[ ], int n) Appends at most n characters of s2 to s1.
36 String Code char first[10] = bobby ; char last[15] = smith ; char name[30]; char you[ ] = bobo ; strcpy( name, first ); strcat( name, last ); printf( %d, %s\n, strlen(name), name ); strncpy( name, last, 2 ); printf( %d, %s\n, strlen(name), name ); int result = strcmp( you, first ); result = strncmp( you, first, 3 ); strcat( first, last );
37 Simple Encryption char c, msg[] = "this is a secret message"; int i = 0; char code[26] = /* Initialize our encryption code */ {'t','f','h','x','q','j','e','m','u','p','i','d','c', 'k','v','b','a','o','l','r','z','w','g','n','s','y'} ; printf ("Original phrase: %s\n", msg); /* Encrypt */ while( msg[i] = '\0 ){ if( isalpha( msg[ i ] ) ) { c = tolower( msg[ i ] ) ; msg[ i ] = code[ c - a ] ; } ++i; } printf("encrypted: %s\n", msg ) ;
38 Arrays of Strings An initialized array of string constants char months[][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" } ; int m; for ( m = 0; m < 12; m++ ) printf( %s\n, months[ m ] ); Alternative: use typedef typedef char Acronym[4] ; Acronym months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" } ;
39 sprintf( ) sprintf( ) works just like printf( ) or fprintf( ), but puts its output into the specified character array. The character array must be big enough. char message[ 100 ]; int myage = 4; sprintf( message, I am %d years old\n, age); printf( %s\n, message);
40 STRUCT
41 Java vs C Suppose you were assigned a write an application about points and straight lines in a coordinate plane. In Java, you d correctly design a Point class and a Line class using composition. What about in C?
42 No Classes in C Because C is not an OOP language, there is no way to combine data and code into a single entity. Related data and functions are form an "Abstract Data Type." Accessibility is enforced by a programmer's good judgment and not by the compiler. C does allow us to combine related data into a structure using the keyword struct. All data in a struct variable can be accessed by any code. Think of a struct as an OOP class in which all data members are public, and which has no methods.
43 Struct definition struct tag { member1_declaration; member2_declaration; member3_declaration;... membern_declaration; }; semi-colon struct is the keyword tag names this kind of struct, member_declarations are variable declarations which define the data members.
44 C struct Example Defining a struct to represent a point in a coordinate plane struct point point is the struct tag { int x;/* x-coordinate */ int y;/* y-coordinate */ }; Given the declarations struct point p1; struct point p2; we can access the members of these struct variables: the x-coordinate of p1 is p1.x the y-coordinate of p1 is p1.y the x-coordinate of p2 is p2.x the y-coordinate of p2 is p2.y
45 Using struct members int main ( ) { struct point lefeendpt, rightendpt, newendpt; printf( Left end point cooridinates ); scanf( %d %d, &lefeendpt.x, &leftendpt.y); printf( Right end point s x-coordinate: ); scanf( %d %d, &righteendpt.x, &rightendpt.y); // add the endpoints newendpt.x = leftendpt.x + rightendpt.x; newendpt.y = leftendpt.y + rightendpt.y; // print new end point printf( New endpoint (%2d, %2d), newendpt.x, newendpt.); } return 0;
46 Initializing a struct struct point middle = { 6, -3 }; is equivalent to struct point middle ; middle.x = 6 ; middle.y = -3 ;
47 struct Variants struct point { int x, y; } endpoint, upperleft ; defines the structure named point AND the variables endpoint and upperleft to be of this type.
48 struct + typedef typedef struct point { int x, y; } POINT; POINT is now a TYPE. POINT endpoint ; is equivalent to struct point endpoint;
49 struct assignment struct point p1; struct point p2; p1.x = 42; p1.y = 59; p2 = p1; /* structure assignment copies members */
50 struct within a struct typedef struct line { POINT leftendpoint; POINT rightendpoint; } LINE; LINE line1, line2; line1.leftendpoint.x = 3 ; line1.leftendpoint.y = 4 ;
51 Arrays of struct LINE lines[5]; // or struct line lines[5]; printf("%d\n", lines[2].leftendpoint.x);
52 Arrays within a struct Structs may contain arrays as well as primitive types struct month { int nrdays; char name[ ]; }; struct month january = { 31, JAN };
53 A bit more complex struct month allmonths[ 12 ] = { {31, JAN }, {28, FEB }, {31, MAR }, {30, APR }, {31, MAY }, {30, JUN }, {31, JUL }, {31, AUG }, {30, SEP }, {31, OCT }, {30, NOV }, {31, DEC } }; // write the code to print the data for September printf( %s has %d days\n, allmonths[8].name, allmonths[8].nrdays); // what is the value of allmonths[3].name[1]
54 Size of a struct As with primitive types, we can use sizeof( ) to determine the number of bytes in a struct int pointsize = sizeof( POINT ); int linesize = sizeof (struct line); As we ll see later, the answers may surprise you
55 NEXT TIME Parameter passing Separate Compilation Scope & Lifetime
File Handling. What is a file?
File Handling 1 What is a file? A named collection of data, stored in secondary storage (typically). Typical operations on files: Open Read Write Close How is a file stored? Stored as sequence of bytes,
More informationASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters
The char Type ASCII Encoding The C char type stores small integers. It is usually 8 bits. char variables guaranteed to be able to hold integers 0.. +127. char variables mostly used to store characters
More informationAs previously noted, a byte can contain a numeric value in the range 0-255. Computers don't understand Latin, Cyrillic, Hindi, Arabic character sets!
Encoding of alphanumeric and special characters As previously noted, a byte can contain a numeric value in the range 0-255. Computers don't understand Latin, Cyrillic, Hindi, Arabic character sets! Alphanumeric
More informationSources: On the Web: Slides will be available on:
C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,
More informationModule 816. File Management in C. M. Campbell 1993 Deakin University
M. Campbell 1993 Deakin University Aim Learning objectives Content After working through this module you should be able to create C programs that create an use both text and binary files. After working
More informationC++ Language Tutorial
cplusplus.com C++ Language Tutorial Written by: Juan Soulié Last revision: June, 2007 Available online at: http://www.cplusplus.com/doc/tutorial/ The online version is constantly revised and may contain
More informationVariables, Constants, and Data Types
Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class: L&L, 2.1-2.3, App C 1 Primitive Data There are eight
More informationIntroduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.
1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays
More informationTopics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:
Introduction to Programming and Algorithms Module 2 CS 146 Sam Houston State University Dr. Tim McGuire Introduction To Computers And Java Chapter Objectives To understand: the meaning and placement of
More informationSo far we have considered only numeric processing, i.e. processing of numeric data represented
Chapter 4 Processing Character Data So far we have considered only numeric processing, i.e. processing of numeric data represented as integer and oating point types. Humans also use computers to manipulate
More informationComputer Programming Tutorial
Computer Programming Tutorial COMPUTER PROGRAMMING TUTORIAL by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL Computer Prgramming Tutorial Computer programming is the act of writing computer
More informationC / C++ and Unix Programming. Materials adapted from Dan Hood and Dianna Xu
C / C++ and Unix Programming Materials adapted from Dan Hood and Dianna Xu 1 C and Unix Programming Today s goals ú History of C ú Basic types ú printf ú Arithmetic operations, types and casting ú Intro
More informationThe programming language C. sws1 1
The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan
More informationInformatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)
More informationSystem Calls and Standard I/O
System Calls and Standard I/O Professor Jennifer Rexford http://www.cs.princeton.edu/~jrex 1 Goals of Today s Class System calls o How a user process contacts the Operating System o For advanced services
More informationIllustration 1: Diagram of program function and data flow
The contract called for creation of a random access database of plumbing shops within the near perimeter of FIU Engineering school. The database features a rating number from 1-10 to offer a guideline
More informationAT&T Global Network Client for Windows Product Support Matrix January 29, 2015
AT&T Global Network Client for Windows Product Support Matrix January 29, 2015 Product Support Matrix Following is the Product Support Matrix for the AT&T Global Network Client. See the AT&T Global Network
More informationLecture 5: Java Fundamentals III
Lecture 5: Java Fundamentals III School of Science and Technology The University of New England Trimester 2 2015 Lecture 5: Java Fundamentals III - Operators Reading: Finish reading Chapter 2 of the 2nd
More informationIntroduction to Java. CS 3: Computer Programming in Java
Introduction to Java CS 3: Computer Programming in Java Objectives Begin with primitive data types Create a main class with helper methods Learn how to call built-in class methods and instance methods
More informationFirst Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science
First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca
More informationBachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)
Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating
More informationAbout The Tutorial. Audience. Prerequisites. Copyright & Disclaimer
About The Tutorial C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system.
More informationThe C Programming Language course syllabus associate level
TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming
More informationStacks. Linear data structures
Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations
More informationC Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands
C Programming for Embedded Microcontrollers Warwick A. Smith Elektor International Media BV Postbus 11 6114ZG Susteren The Netherlands 3 the Table of Contents Introduction 11 Target Audience 11 What is
More informationHow To Write Portable Programs In C
Writing Portable Programs COS 217 1 Goals of Today s Class Writing portable programs in C Sources of heterogeneity Data types, evaluation order, byte order, char set, Reading period and final exam Important
More informationMemory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example
Announcements Memory management Assignment 2 posted, due Friday Do two of the three problems Assignment 1 graded see grades on CMS Lecture 7 CS 113 Spring 2008 2 Safe user input If you use scanf(), include
More informationMolecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct
Dr. Martin O. Steinhauser University of Basel Graduate Lecture Spring Semester 2014 Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct Friday, 7 th March
More informationC++ Input/Output: Streams
C++ Input/Output: Streams 1 The basic data type for I/O in C++ is the stream. C++ incorporates a complex hierarchy of stream types. The most basic stream types are the standard input/output streams: istream
More informationCOMPARISON OF FIXED & VARIABLE RATES (25 YEARS) CHARTERED BANK ADMINISTERED INTEREST RATES - PRIME BUSINESS*
COMPARISON OF FIXED & VARIABLE RATES (25 YEARS) 2 Fixed Rates Variable Rates FIXED RATES OF THE PAST 25 YEARS AVERAGE RESIDENTIAL MORTGAGE LENDING RATE - 5 YEAR* (Per cent) Year Jan Feb Mar Apr May Jun
More informationCOMPARISON OF FIXED & VARIABLE RATES (25 YEARS) CHARTERED BANK ADMINISTERED INTEREST RATES - PRIME BUSINESS*
COMPARISON OF FIXED & VARIABLE RATES (25 YEARS) 2 Fixed Rates Variable Rates FIXED RATES OF THE PAST 25 YEARS AVERAGE RESIDENTIAL MORTGAGE LENDING RATE - 5 YEAR* (Per cent) Year Jan Feb Mar Apr May Jun
More informationCS 106 Introduction to Computer Science I
CS 106 Introduction to Computer Science I 01 / 21 / 2014 Instructor: Michael Eckmann Today s Topics Introduction Homework assignment Review the syllabus Review the policies on academic dishonesty and improper
More informationLecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c
Lecture 3 Data structures arrays structs C strings: array of chars Arrays as parameters to functions Multiple subscripted arrays Structs as parameters to functions Default arguments Inline functions Redirection
More informationBasics of I/O Streams and File I/O
Basics of This is like a cheat sheet for file I/O in C++. It summarizes the steps you must take to do basic I/O to and from files, with only a tiny bit of explanation. It is not a replacement for reading
More informationPemrograman Dasar. Basic Elements Of Java
Pemrograman Dasar Basic Elements Of Java Compiling and Running a Java Application 2 Portable Java Application 3 Java Platform Platform: hardware or software environment in which a program runs. Oracle
More informationCSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals
CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]
More informationHandout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.
Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java
More informationPART-A Questions. 2. How does an enumerated statement differ from a typedef statement?
1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members
More informationObject-Oriented Programming in Java
CSCI/CMPE 3326 Object-Oriented Programming in Java Class, object, member field and method, final constant, format specifier, file I/O Dongchul Kim Department of Computer Science University of Texas Rio
More informationEmbedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C
Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection
More informationName: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.
Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to
More information2 ASCII TABLE (DOS) 3 ASCII TABLE (Window)
1 ASCII TABLE 2 ASCII TABLE (DOS) 3 ASCII TABLE (Window) 4 Keyboard Codes The Diagram below shows the codes that are returned when a key is pressed. For example, pressing a would return 0x61. If it is
More informationPerl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl
First CGI Script and Perl Perl in a nutshell Prof. Rasley shebang line tells the operating system where the Perl interpreter is located necessary on UNIX comment line ignored by the Perl interpreter End
More informationNumber Representation
Number Representation CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Topics to be Discussed How are numeric data
More informationEnhanced Vessel Traffic Management System Booking Slots Available and Vessels Booked per Day From 12-JAN-2016 To 30-JUN-2017
From -JAN- To -JUN- -JAN- VIRP Page Period Period Period -JAN- 8 -JAN- 8 9 -JAN- 8 8 -JAN- -JAN- -JAN- 8-JAN- 9-JAN- -JAN- -JAN- -JAN- -JAN- -JAN- -JAN- -JAN- -JAN- 8-JAN- 9-JAN- -JAN- -JAN- -FEB- : days
More informationChapter 2: Elements of Java
Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction
More informationarrays C Programming Language - Arrays
arrays So far, we have been using only scalar variables scalar meaning a variable with a single value But many things require a set of related values coordinates or vectors require 3 (or 2, or 4, or more)
More informationIntroduction to Java
Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high
More informationInstall Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html
CS 259: Data Structures with Java Hello World with the IntelliJ IDE Instructor: Joel Castellanos e-mail: joel.unm.edu Web: http://cs.unm.edu/~joel/ Office: Farris Engineering Center 319 8/19/2015 Install
More informationPROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE
PROGRAMMING IN C CONTENT AT A GLANCE 1 MODULE 1 Unit 1 : Basics of Programming Unit 2 : Fundamentals Unit 3 : C Operators MODULE 2 unit 1 : Input Output Statements unit 2 : Control Structures unit 3 :
More information6.170 Tutorial 3 - Ruby Basics
6.170 Tutorial 3 - Ruby Basics Prerequisites 1. Have Ruby installed on your computer a. If you use Mac/Linux, Ruby should already be preinstalled on your machine. b. If you have a Windows Machine, you
More informationChapter One Introduction to Programming
Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of
More information5 Arrays and Pointers
5 Arrays and Pointers 5.1 One-dimensional arrays Arrays offer a convenient way to store and access blocks of data. Think of arrays as a sequential list that offers indexed access. For example, a list of
More informationAnalysis One Code Desc. Transaction Amount. Fiscal Period
Analysis One Code Desc Transaction Amount Fiscal Period 57.63 Oct-12 12.13 Oct-12-38.90 Oct-12-773.00 Oct-12-800.00 Oct-12-187.00 Oct-12-82.00 Oct-12-82.00 Oct-12-110.00 Oct-12-1115.25 Oct-12-71.00 Oct-12-41.00
More informationIntroduction to Data Structures
Introduction to Data Structures Albert Gural October 28, 2011 1 Introduction When trying to convert from an algorithm to the actual code, one important aspect to consider is how to store and manipulate
More informationMATLAB: Strings and File IO
MATLAB: Strings and File IO Kipp Martin University of Chicago Booth School of Business February 9, 2012 The M-files The following files are used in this lecture. filein.txt fileio.m Outline Strings File
More informationCase 2:08-cv-02463-ABC-E Document 1-4 Filed 04/15/2008 Page 1 of 138. Exhibit 8
Case 2:08-cv-02463-ABC-E Document 1-4 Filed 04/15/2008 Page 1 of 138 Exhibit 8 Case 2:08-cv-02463-ABC-E Document 1-4 Filed 04/15/2008 Page 2 of 138 Domain Name: CELLULARVERISON.COM Updated Date: 12-dec-2007
More information60-141 Introduction to Programming II Winter, 2014 Assignment 2
60-141 Introduction to Programming II Winter, 2014 Assignment 2 Array In this assignment you will implement an encryption and a corresponding decryption algorithm which involves only random shuffling of
More informationWe will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.
LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.
More informationChapter 2. println Versus print. Formatting Output withprintf. System.out.println for console output. console output. Console Input and Output
Chapter 2 Console Input and Output System.out.println for console output System.out is an object that is part of the Java language println is a method invoked dby the System.out object that can be used
More informationUniversity of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python
Introduction Welcome to our Python sessions. University of Hull Department of Computer Science Wrestling with Python Week 01 Playing with Python Vsn. 1.0 Rob Miles 2013 Please follow the instructions carefully.
More informationCP Lab 2: Writing programs for simple arithmetic problems
Computer Programming (CP) Lab 2, 2015/16 1 CP Lab 2: Writing programs for simple arithmetic problems Instructions The purpose of this Lab is to guide you through a series of simple programming problems,
More informationELEC3730 Embedded Systems Lecture 1: Introduction and C Essentials
ELEC3730 Embedded Systems Lecture 1: Introduction and C Essentials Overview of Embedded Systems Essentials of C programming - Lecture 1 1 Embedded System Definition and Examples Embedded System Definition:
More informationC Strings and Pointers
Motivation The C++ string class makes it easy to create and manipulate string data, and is a good thing to learn when rst starting to program in C++ because it allows you to work with string data without
More informationSimple Image File Formats
Chapter 2 Simple Image File Formats 2.1 Introduction The purpose of this lecture is to acquaint you with the simplest ideas in image file format design, and to get you ready for this week s assignment
More informationJava Basics: Data Types, Variables, and Loops
Java Basics: Data Types, Variables, and Loops If debugging is the process of removing software bugs, then programming must be the process of putting them in. - Edsger Dijkstra Plan for the Day Variables
More informationObjective-C Tutorial
Objective-C Tutorial OBJECTIVE-C TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL Objective-c tutorial Objective-C is a general-purpose, object-oriented programming
More informationLecture 22: C Programming 4 Embedded Systems
Lecture 22: C Programming 4 Embedded Systems Today s Goals Basic C programming process Variables and constants in C Pointers to access addresses Using a High Level Language High-level languages More human
More informationChapter 3. Input and output. 3.1 The System class
Chapter 3 Input and output The programs we ve looked at so far just display messages, which doesn t involve a lot of real computation. This chapter will show you how to read input from the keyboard, use
More informationSimple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language
Simple C++ Programs Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input and Output Basic Functions from
More informationProgramming Microcontrollers in C
Programming Microcontrollers in C Second Edition Ted Van Sickle A Volume in the EMBEDDED TECHNOLOGY TM Series Eagle Rock, Virginia www.llh-publishing.com Programming Microcontrollers in C 2001 by LLH Technology
More informationPassing 1D arrays to functions.
Passing 1D arrays to functions. In C++ arrays can only be reference parameters. It is not possible to pass an array by value. Therefore, the ampersand (&) is omitted. What is actually passed to the function,
More information/* File: blkcopy.c. size_t n
13.1. BLOCK INPUT/OUTPUT 505 /* File: blkcopy.c The program uses block I/O to copy a file. */ #include main() { signed char buf[100] const void *ptr = (void *) buf FILE *input, *output size_t
More informationLOW LEVEL FILE PROCESSING
LOW LEVEL FILE PROCESSING 1. Overview The learning objectives of this lab session are: To understand the functions provided for file processing by the lower level of the file management system, i.e. the
More informationC Examples! Jennifer Rexford!
C Examples! Jennifer Rexford! 1 Goals of this Lecture! Help you learn about:! The fundamentals of C! Deterministic finite state automata (DFA)! Expectations for programming assignments! Why?! The fundamentals
More informationPHP Debugging. Draft: March 19, 2013 2013 Christopher Vickery
PHP Debugging Draft: March 19, 2013 2013 Christopher Vickery Introduction Debugging is the art of locating errors in your code. There are three types of errors to deal with: 1. Syntax errors: When code
More informationHow To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)
TN203 Porting a Program to Dynamic C Introduction Dynamic C has a number of improvements and differences compared to many other C compiler systems. This application note gives instructions and suggestions
More informationProgramming in C an introduction
Programming in C an introduction PRC for E Maarten Pennings Version 0.5 (2007-12-31) 0 0 Preface This book explains the C programming language. It assumes no programming knowledge. The reader is supposed
More informationHow To Write A Program In Php 2.5.2.5 (Php)
Exercises 1. Days in Month: Write a function daysinmonth that takes a month (between 1 and 12) as a parameter and returns the number of days in that month in a non-leap year. For example a call to daysinmonth(6)
More informationTutorial on C Language Programming
Tutorial on C Language Programming Teodor Rus rus@cs.uiowa.edu The University of Iowa, Department of Computer Science Introduction to System Software p.1/64 Tutorial on C programming C program structure:
More informationLecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists
Lecture 11 Doubly Linked Lists & Array of Linked Lists In this lecture Doubly linked lists Array of Linked Lists Creating an Array of Linked Lists Representing a Sparse Matrix Defining a Node for a Sparse
More informationKeywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void
1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of
More informationLexical Analysis and Scanning. Honors Compilers Feb 5 th 2001 Robert Dewar
Lexical Analysis and Scanning Honors Compilers Feb 5 th 2001 Robert Dewar The Input Read string input Might be sequence of characters (Unix) Might be sequence of lines (VMS) Character set ASCII ISO Latin-1
More informationC PROGRAMMING FOR MATHEMATICAL COMPUTING
UNIVERSITY OF CALICUT SCHOOL OF DISTANCE EDUCATION BSc MATHEMATICS (2011 Admission Onwards) VI Semester Elective Course C PROGRAMMING FOR MATHEMATICAL COMPUTING QUESTION BANK Multiple Choice Questions
More informationVB.NET Programming Fundamentals
Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements
More informationBuilding Java Programs
Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: 3.3-3.4 self-check: #16-19 exercises: #11 videos: Ch. 3 #4 Interactive programs We have written programs that print
More informationScanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.
Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input
More informationSimple C Programs. Goals for this Lecture. Help you learn about:
Simple C Programs 1 Goals for this Lecture Help you learn about: Simple C programs Program structure Defining symbolic constants Detecting and reporting failure Functionality of the gcc command Preprocessor,
More informationCS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013
Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)
More informationLex et Yacc, exemples introductifs
Lex et Yacc, exemples introductifs D. Michelucci 1 LEX 1.1 Fichier makefile exemple1 : exemple1. l e x f l e x oexemple1. c exemple1. l e x gcc o exemple1 exemple1. c l f l l c exemple1 < exemple1. input
More informationChapter 4: Computer Codes
Slide 1/30 Learning Objectives In this chapter you will learn about: Computer data Computer codes: representation of data in binary Most commonly used computer codes Collating sequence 36 Slide 2/30 Data
More informationProgramming languages C
INTERNATIONAL STANDARD ISO/IEC 9899:1999 TECHNICAL CORRIGENDUM 2 Published 2004-11-15 INTERNATIONAL ORGANIZATION FOR STANDARDIZATION МЕЖДУНАРОДНАЯ ОРГАНИЗАЦИЯ ПО СТАНДАРТИЗАЦИИ ORGANISATION INTERNATIONALE
More informationC++ Programming Language
C++ Programming Language Lecturer: Yuri Nefedov 7th and 8th semesters Lectures: 34 hours (7th semester); 32 hours (8th semester). Seminars: 34 hours (7th semester); 32 hours (8th semester). Course abstract
More informationAdvanced Bash Scripting. Joshua Malone (jmalone@ubergeeks.com)
Advanced Bash Scripting Joshua Malone (jmalone@ubergeeks.com) Why script in bash? You re probably already using it Great at managing external programs Powerful scripting language Portable and version-stable
More informationpublic static void main(string[] args) { System.out.println("hello, world"); } }
Java in 21 minutes hello world basic data types classes & objects program structure constructors garbage collection I/O exceptions Strings Hello world import java.io.*; public class hello { public static
More informationComp151. Definitions & Declarations
Comp151 Definitions & Declarations Example: Definition /* reverse_printcpp */ #include #include using namespace std; int global_var = 23; // global variable definition void reverse_print(const
More informationHow To Write A Programming Program
1 Preface... 6 Preface to the first edition...8 Chapter 1 - A Tutorial Introduction...9 1.1 Getting Started...9 1.2 Variables and Arithmetic Expressions...11 1.3 The for statement...15 1.4 Symbolic Constants...17
More informationBoolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)
Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the
More informationVersion 1.5 Satlantic Inc.
SatCon Data Conversion Program Users Guide Version 1.5 Version: 1.5 (B) - March 09, 2011 i/i TABLE OF CONTENTS 1.0 Introduction... 1 2.0 Installation... 1 3.0 Glossary of terms... 1 4.0 Getting Started...
More information