C Language Summary HTML version. I/O Data Types Expressions Functions Loops and Decisions Preprocessor Statements.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

A C++ Crash Course Part II UW Association for Computing Machinery Questions & Feedback.
Introduction to C Systems Programming Concepts. Introduction to C A simple C Program A simple C Program –Variable Declarations –printf ( ) Compiling and.
Using Files Declare a variable, called file pointer, of type FILE * Use function fopen to open a named file and associate this file with the file pointer.
Week 5 Part I Kyle Dewey. Overview Exam will be back Thursday New office hour More on functions File I/O Project #2.
C Language.
Files in C Rohit Khokher.
Engineering EG167C - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect M1 P. 1Winter Quarter Midterm I Review.
1 Chapter 10 Strings and Pointers. 2 Introduction  String Constant  Example: printf(“Hello”); “Hello” : a string constant oA string constant is a series.
BITS Pilani, Pilani Campus TA C252 Computer Programming - II Vikas Singh File Handling.
Files in C Rohit Khokher. Files in C Real life situations involve large volume of data and in such cases, the console oriented I/O operations pose two.
C Programming Revision Malcolm Wilson. Variables Types int, char, double, long. NO type for string see later. unsigned above. assignment X=2 ; C=‘v’;
C Programming - Lecture 3 File handling in C - opening and closing. Reading from and writing to files. Special file streams stdin, stdout & stderr. How.
CSSE221: Software Dev. Honors Day 27 Announcements Announcements Projects turned in? Projects turned in? The 2 required Angel surveys are due by 9 pm tonight.
Structures and Unions Chapter 6. Structure A structure is an aggregate data type  Composed of two or more related variables called member/field/element.
The little language that could Remember C is a “small language”
Guide To UNIX Using Linux Third Edition
Programming in C #2 Input / Output.
Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common.
Console and File I/O - Basics Rudra Dutta CSC Spring 2007, Section 001.
An Introduction to C Programming (assuming that you already know Java; this is not an introduction to C++)
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
By Sidhant Garg.  C was developed between by Dennis Ritchie at Bell Laboratories for use with the Unix Operating System.  Unlike previously.
C Basic File Input/Output Manipulation C Programming – File Outline v File handling in C - opening and closing. v Reading from and writing to files.
Lone Leth Thomsen Input / Output and Files. April 2006Basis-C-8/LL2 sprintf() and sscanf() The functions sprintf() and sscanf() are string versions of.
CP104 Introduction to Programming File I/O Lecture 33 __ 1 File Input/Output Text file and binary files File Input/output File input / output functions.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 7P. 1Winter Quarter File I/O in C Lecture.
C STRUCTURES. A FIRST C PROGRAM  #include  void main ( void )  { float height, width, area, wood_length ;  scanf ( "%f", &height ) ;  scanf ( "%f",
File IO and command line input CSE 2451 Rong Shi.
Lecture 1 cis208 January 14 rd, Compiling %> gcc helloworld.c returns a.out %> gcc –o helloworld helloworld.c returns helloworld.
1 File Handling. 2 Storage seen so far All variables stored in memory Problem: the contents of memory are wiped out when the computer is powered off Example:
DATA TYPE AND DISPLAY Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Introduction As programmers, we don’t want to have to implement functions for every possible task we encounter. The Standard C library contains functions.
Chapter 3 Input and Output
Chapter 7 : File Processing1 File-Oriented Input & Output CHAPTER 7.
1 CHAPTER6 CHAPTER 6. Objectives: You’ll learn about;  Introduction  Files and streams  Creating a sequential access file  Reading data from a sequential.
Lecture 11: Files & Arrays B Burlingame 18 November 2015.
24-2 Perform File I/O using file pointers FILE * data-type Opening and closing files Character Input and Output String Input and Output Related Chapter:
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
C LANGUAGE Characteristics of C · Small size
Gramming An Introduction to C Programming (assuming that you already know Java; this is not an introduction to C++)
CS 1704 Introduction to Data Structures and Software Engineering.
Files A collection of related data treated as a unit. Two types Text
C is a high level language (HLL)
Lecture 20: C File Processing. Why Using Files? Storage of data in variables and arrays is temporary Data lost when a program terminates. Files are used.
Connecting to Files In order to read or write to a file, we need to make a connection to it. There are several functions for doing this. fopen() – makes.
An Introduction to C Programming (assuming that you already know Java; this is not an introduction to C++)
A bit of C programming Lecture 3 Uli Raich.
Chapter 22 – part a Stream refer to any source of input or any destination for output. Many small programs, obtain all their input from one stream usually.
File Access (7.5) CSE 2031 Fall July 2018.
An Introduction to C Programming
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
C Short Overview Lembit Jürimägi.
CS111 Computer Programming
File Input/Output.
Computer Programming Lecture 15 Text File I/O
DATA HANDLING.
Programming in C Input / Output.
C: Primer and Advanced Topics
Programming in C Input / Output.
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
Chapter: 7-12 Final exam review.
Programming in C Input / Output.
File Handling in C.
Module 12 Input and Output
Programming Languages and Paradigms
Quick Review EECS May 2019.
C Language B. DHIVYA 17PCA140 II MCA.
C Programming - Lecture 3
Files Chapter 8.
Presentation transcript:

C Language Summary HTML version

I/O Data Types Expressions Functions Loops and Decisions Preprocessor Statements

0. I/O: Output printf( “ format_list ”, var_list ); All formats are of the form: %w.px%w.px where w.p is optional and can be *.* (value given by next 2 arguments ). w  field width p  the precision x  d (integer), f (decimal ), e (e-format), g (g-format), s (string), c (character) …

0. I/O: Input scanf( “ format_list ”, pointer_list ); Notes: &var is a pointer pointing to the variable var. Separators can be specified in the format_list. e.g., “%d:%d” expects input of 2 integers separated by an :. A string variable is already a pointer so that no preceding & is needed.

0. I/O: fopen #include  stdio.h  /* for the fopen() */ #include  stdlib.h  /* for the exit() */ int main( int argc, char* argv[] ) { FILE *in_file, *fopen( ); in_file  fopen( “file_name”, ”w+” );/* in_file is the file handle */ if ( in_file   NULL ) { printf( “ Can’t open file. \n” ); exit(1);/* program is terminated with exit code equal to 1 */ } fprintf( in_file, "Hello World!\n"); return 0; }

0. I/O: rewind fclose fprintf scanf rewind( in_file ); fclose( in_file ); fprintf( out_file, “ format_list ”, var_list ); Note: printf is fprintf with out_file  stdout. fscanf( in_file, “ format_list ”, var_list ); Note: scanf is fscanf with in_file  stdin IO.c

1. Data Types: Basic Data Types Declaration & initialization ( can be placed anywhere ): type var1  initial_value1, …, varN  initial_valueN; Assignment: var1  var2  …  value;

TypeModifiers intshort, long, unsigned floatlong (double) charunsigned void  Basic Data Types

Derived Data Types: Arrays Declaration & initialization: type var[n]  { var[0], …, var[n-1] }; /* RHS is the initial value of the array */ char cvar[ ]  “String”; type var[n][m]  { { var[0][0], …, var[0][m-1] }, …, { var[n-1][0], …, var[n-1][m-1] } };

Structures Definition & declaration: struct structure_name { member1_declaration; … memberN_declaration; } var_list;

Declaration: struct structure_name var_list; Definition, declaration & initialization: struct structure_name { member1_declaration; … memberN_declaration; } var  { member1  value1, …, memberN  valueN };

Unions Every member of a union shares the same memory space. Definition & declaration: union union_name { member1_declaration; … memberN_declaration; } var_list; Declaration: union union _name var_list;

Pointers Definition: type *pointer_name; /* The ‘*’ denotes a pointer variable */ Example: struct struct_name ( *fn_pointer ) ( ) ; declares fn_pointer to be a pointer to a function that returns a struct_name structure.

Enumerated Data Types Definition & declaration: enum enum_name { enum_1, …, enum_N } var_list; Declaration: enum enum _name var_list;

typedef typedef assigns a new name to a datatype. Example: typedef struct { member1_declaration; … memberN_declaration; } struct_name; struct_name var; /* This declares var to be a struct_name structure. */