Standard Libraries in C

Slides:



Advertisements
Similar presentations
Memory and Files Dr. Andrew Wallace PhD BEng(hons) EurIng
Advertisements

Text File Input and Output. Overview Text File Buffered I/O Functions fopen Function Demo of File Write and Read.
Lecture 10 ctype.h, Exercises METU Dept. of Computer Eng. Summer 2002 Ceng230 - Section 01 Introduction To C Programming by Ahmet Sacan Wed July 31, 2002.
Fungsi Risanuri Hidayat, Ir., M.Sc.. Functions C usually consist of two things: instance variables and functions. All C programs consist of one or more.
Strings, Arrays, and Pointers CS-2303, C-Term Strings, Arrays, and Pointers CS-2303 System Programming Concepts (Slides include materials from The.
1 Homework / Exam HW7 due class 25 Exam 3 - class 26 –Open Book, Open Notes –Covers up through end of K&R 7 –and Appendix B Standard Library –Plus UNIX.
Strings, Arrays, and Pointers CS-2301 D-term Strings, Arrays, and Pointers CS-2301 System Programming C-term 2009 (Slides include materials from.
Contents 1. Preface/Introduction 2. Standardization and Implementation 3. File I/O   4. Standard I/O Library 5. Files and Directories 6. System Data.
1 Modularity The material for this lecture is drawn, in part, from The Practice of Programming (Kernighan & Pike) Chapter 4.
Strings, Arrays, and Pointers CS-2301, B-Term Strings, Arrays, and Pointers CS-2301, System Programming for Non-Majors (Slides include materials.
 2000 Prentice Hall, Inc. All rights reserved. Functions in C Outline 1Introduction 2Program Modules in C 3Math Library Functions 4Functions 5Function.
Introduction to C programming
CHAPTER 8 CHARACTER AND STRINGS
C++ Standard Library Includes derivatives of Standard C Library
C for Java Programmers Tomasz Müldner Copyright:  Addison-Wesley Publishing Company, : Pointers and Functions Pointer Parameters: Pass by Value.
CS-1030 Dr. Mark L. Hornick 1 History of C Ref: “The Development of the C Language” – Dennis Ritchie Summary of C (and Unix) History ATT-Bell Labs/GE.
Functions in C Outline 1Introduction 2Program Modules in C 3Math Library Functions 4Functions 5Function Definitions 6Function Prototypes 7Header Files.
String Library Calls (Representative, not Exhaustive) Rudra Dutta CSC Spring 2007, Section 001.
Week 2 - Friday.  What did we talk about last time?  Base systems  C literals  Representations in memory.
1 Lecture09: File I/O 5/6/2013 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
Characters and Strings File Processing Exercise C Programming:Part 3.
File IO and command line input CSE 2451 Rong Shi.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee C Language Part 4.
1 Lecture09: File I/O 11/19/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
Spring 2005, Gülcihan Özdemir Dağ Lecture 8, Page 1 BIL104E: Introduction to Scientific and Engineering Computing, Spring Lecture 8 Outline 8.1 Declaring.
FILE IO in ‘C’ by Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
Mobility Research Lab mobility.ceng.metu.edu.tr Applied Innovative Interdisciplinary (AI2) Research Lab Short Course on Programming in C/C++
C Programming Lecture 12 : File Processing
1 Modularity Heuristics The material for this lecture is drawn, in part, from The Practice of Programming (Kernighan & Pike) Chapter 4 Jennifer Rexford.
CTYPE.H Introduction  The ctype header is used for testing and converting characters.  A control character refers to a character that.
Sudeshna Sarkar, IIT Kharagpur 1 I/O in C + Misc Lecture –
Advanced Programming in the UNIX Environment Hop Lee.
ECE Application Programming
Characters, Strings, and the cstring Library
INC 161 , CPE 100 Computer Programming
Strings, Arrays, and Pointers
Type casting Algorithm & flowchart
Characters, Strings, and the cstring Library
ECE Application Programming
Lecture 11 File input/output
Chapter 4 Mathematical Functions, Characters, and Strings
Functions, Part 2 of 2 Topics Functions That Return a Value
Programming and Data Structures
ECE Application Programming
CGS 3460, Lecture 41 Apr 21, 2006 Hen-I Yang
Input / Output functions in C
CSC215 Lecture Input and Output.
I/O in C + Misc Lecture Sudeshna Sarkar, IIT Kharagpur.
C Programming:Part 3 Characters and Strings File Processing Exercise.
2008/11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park
CSC215 Lecture Introduction.
Input / Output functions in C
CSC215 Lecture Input and Output.
CSC215 Lecture Input and Output.
CS 161 Introduction to Programming
Functions, Part 2 of 3 Topics Functions That Return a Value
CSC215 Lecture Introduction.
Henning Schulzrinne Columbia University
Strings in C Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
The Standard Library Chapter 21
EECE.2160 ECE Application Programming
C By Example The assumption is that you know Java and need to extend that knowledge so you can program in C. 1. Hello world 2. declarations 3. pass.
Modularity Jennifer Rexford
CSC215 Lecture Introduction.
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Functions, Part 2 of 3 Topics Functions That Return a Value
Functions, Part 2 of 3 Topics Functions That Return a Value
EECE.2160 ECE Application Programming
Functions in C Math Library Functions Functions Function Definitions
Presentation transcript:

Standard Libraries in C CSC215 Lecture Standard Libraries in C

Outline Introduction stdio.h stdlib.h ctype.h stdarg.h math.h String.h assert.h error.h time.h

Introduction Standard libraries: type definitions variable declarations constant and macro definitions Functions Description and usage information can be obtained from man pages on unix-like OS or the web section 3 on unix and unix-like OS: in the terminal type: man [<section>] <library_function_name>⏎ Many websites host copies of the man pages: Die, HE , MAN7 , … List of standard libraries: assert.h ctype.h errno.h float.h limits.h locale.h math.h setjmp.h signal.h stdarg.h stddef.h stdio.h stdlib.h string.h time.h

Library stdio.h Types Constants Functions size_t FILE NULL EOF SEEK_CUR SEEK_END SEEK_SET stderr stdin stdout Functions FILE *fopen(const char *, const char *) int fclose(FILE *) int fflush(FILE *) ---------------------------------------------------- int getchar(void) char *gets(char *) int scanf(const char *, ...) int putchar(int char) int puts(const char *) int printf(const char *, ...) ---------------------------------------------------- int fgetc(FILE *) int ungetc(int char, FILE *stream) char *fgets(char *, int , FILE *) int fscanf(FILE *, const char *, ...) int fputc(int, FILE *) int fputs(const char *, FILE *) int fprintf(FILE *, const char *, ...)

Library stdio.h Functions (cont.) size_t fread(void *, size_t, size_t, FILE *) size_t fwrite(const void *, size_t, size_t, FILE *) ---------------------------------------------------- void rewind(FILE *) int fseek(FILE *, long int, int) int fgetpos(FILE *, fpos_t *) int fsetpos(FILE *, const fpos_t *) long int ftell(FILE *) int remove(const char *) int rename(const char *, const char *)

Library stdlib.h Types Constants Functions (cont.) size_t NULL EXIT_FAILURE EXIT_SUCCESS RAND_MAX Functions (cont.) void *malloc(size_t) void *calloc(size_t, size_t) void *realloc(void *, size_t) void free(void *) ---------------------------------------------------- double atof(const char *) int atoi(const char *) long int atol(const char *) double strtod(const char *, char **) long int strtol(const char *, char **, int) unsigned long int strtoul(const char *, char **, int) void abort(void) void exit(int) int atexit(void (*func)(void)) int system(const char *string) int abs(int x) long int labs(long int x)

Library stdlib.h Functions (cont.) int rand(void) void srand(unsigned int seed) ---------------------------------------------------- void *bsearch(const void *, const void *, size_t, size_t, int (*compar)(const void *, const void *)) void qsort(void *, size_t, size_t, int (*compar)(const void *, const void*))

Library ctype.h Functions (cont.) 0 1 2 3 4 5 6 7 8 9 int isalnum(int c) int isalpha(int c) int iscntrl(int c) int isdigit(int c) int isgraph(int c) int islower(int c) int isprint(int c) int ispunct(int c) int isspace(int c) int isupper(int c) int isxdigit(int c) ------------------- int tolower(int c) int toupper(int c) Digits Uppercase Letters Lowercase Letters 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z A b c d e f g h i j k l m n o p q r s t u v w x y z ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~ ' ' \t \n \v \f \r \0 \037 \177 Punctuations Space characters Control characters Graphical characters Hexadecimal Alphabetic Printable

Library stdarg.h Types Macros va_list void va_start(va_list, last_arg) type va_arg(va_list, type) void va_end(va_list) void va_copy(va_list, va_list)

Library math.h Arithmetic functions Exponential functions double fabs(double ) |x| double ceil(double ) ⌈x⌉ double floor(double ) ⌊x⌋ double fmod(double , double ) x%y double modf(double , double *) x-⌊x⌋ , ⌊x⌋ Exponential functions double pow(double , double ) xy double sqrt(double ) √x double exp(double ) ex double ldexp(double , int ) x.2y double log(double ) logex double log10(double ) log10x Trigonometric functions double sin(double ) sin(x) double cos(double ) cos(x) double asin(double ) sin-1(x) double acos(double ) cos-1(x) double atan(double ) tan-1(x) All functions take and yields double precision floating point values. Trigonometric functions deals with input and output angles in radians.

Example

Library string.h Memory functions String functions int memcmp(const void *, const void *, size_t) void *memchr(const void *, int, size_t) void *memcpy(void *, const void *, size_t) void *memset(void *, int, size_t ) String functions size_t strlen(const char *) char *strcat(char *, const char *) char *strncat(char *, const char *, size_t ) char *strcpy(char *, const char *) char *strncpy(char *, const char *, size_t ) int strcmp(const char *, const char *) int strncmp(const char *, const char *, size_t ) char *strchr(const char *, int) char *strrchr(const char *, int) char *strstr(const char *, const char *) char *strpbrk(const char *, const char *) size_t strspn(const char *, const char *) size_t strcspn(const char *, const char *) char *strtok(char *, const char *) In coping functions, the first parameter is the destination and the second is the source. In search functions, first parameter is the haystack (text) and the second is the needle (pattern).

Example

Libraries: assert.h, error.h and time.h Macro of assert.h void assert(int expression) Macro of error.h extern int errno Types of time.h clock_t time_t Struct tm Functions of time.h clock_t clock() time_t time(time_t*) double difftime(time_t, time_t) time_t mktime(struct tm*) char* asctime(const struct tm*) char* ctime(const time_t) struct tm* gmtime(const time_t) struct tm* localtime(const time_t ) size_t strftime(char* , size_t , const char* , const struct tm* )