C mini reference. 5 Binary numbers 12

Similar documents
C Libraries. Bart Childs Complementary to the text(s)

Chapter 8 C Characters and Strings

C: How to Program. Week /May/28

Standard C Library Functions

Chapter 8 - Characters and Strings

C PROGRAMMING. Characters and Strings File Processing Exercise

ECE551 Midterm Version 1

Characters and Strings

Chapter 8: Character & String. In this chapter, you ll learn about;

Fundamentals of Programming. Lecture 11: C Characters and Strings

System Software Experiment 1 Lecture 7

Arrays, Strings, & Pointers

Course organization. Course introduction ( Week 1)

C Characters and Strings

today cs3157-fall2002-sklar-lect05 1

C programming basics T3-1 -

ECE551 Midterm Version 2

Scientific Programming in C V. Strings

Input / Output Functions

8. Characters, Strings and Files

C Programming. Unit 9. Manipulating Strings File Processing.

SWEN-250 Personal SE. Introduction to C

UNIT IV-2. The I/O library functions can be classified into two broad categories:

ch = argv[i][++j]; /* why does ++j but j++ does not? */

File IO and command line input CSE 2451

Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types

Standard File Pointers

A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called.

CS 261 Fall Mike Lam, Professor. Structs and I/O

211: Computer Architecture Summer 2016

MARKS: Q1 /20 /15 /15 /15 / 5 /30 TOTAL: /100

Procedural Programming

by Pearson Education, Inc. All Rights Reserved.

Contents. Preface. Introduction. Introduction to C Programming

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

ECE 551D Spring 2018 Midterm Exam

Strings(2) CS 201 String. String Constants. Characters. Strings(1) Initializing and Declaring String. Debzani Deb

Converting a Lowercase Letter Character to Uppercase (Or Vice Versa)

ENG120. Misc. Topics

ECE551 Midterm Version 1

Strings. Arrays of characters. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY

Characters, c-strings, and the string Class. CS 1: Problem Solving & Program Design Using C++

Computer Programming

Systems Programming. 08. Standard I/O Library. Alexander Holupirek

Signature: ECE 551 Midterm Exam

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

CSCI 171 Chapter Outlines

Introduction to C/C++ Lecture 5 - String & its Manipulation

System Design and Programming II

C strings. (Reek, Ch. 9) 1 CS 3090: Safety Critical Programming in C

CS240: Programming in C

Introduction to string

ECE551 Midterm. There are 7 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly.

Approximately a Test II CPSC 206

Input/Output and the Operating Systems

Files and Streams Opening and Closing a File Reading/Writing Text Reading/Writing Raw Data Random Access Files. C File Processing CS 2060

Outline. Computer Programming. Structure of a function. Functions. Function prototype. Structure of a function. Functions

Strings and Library Functions

7/21/ FILE INPUT / OUTPUT. Dong-Chul Kim BioMeCIS UTA

Introduction to file management

Announcements. Strings and Pointers. Strings. Initializing Strings. Character I/O. Lab 4. Quiz. July 18, Special character arrays

Accessing Files in C. Professor Hugh C. Lauer CS-2303, System Programming Concepts

Mode Meaning r Opens the file for reading. If the file doesn't exist, fopen() returns NULL.

ECE 551D Spring 2018 Midterm Exam

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).

Structured programming

ELEC / COMP 177 Fall Some slides from Kurose and Ross, Computer Networking, 5 th Edition

File I/O. Arash Rafiey. November 7, 2017

ONE DIMENSIONAL ARRAYS

Chapter 12. Files (reference: Deitel s chap 11) chap8

Appendix A Developing a C Program on the UNIX system

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

CS3157: Advanced Programming. Outline

CSC209H Lecture 3. Dan Zingaro. January 21, 2015

Contents. A Review of C language. Visual C Visual C++ 6.0

CSCE150A. Introduction. Basics. String Library. Substrings. Line Scanning. Sorting. Command Line Arguments. Misc CSCE150A. Introduction.

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Computer Science & Engineering 150A Problem Solving Using Computers. Chapter 9. Strings. Notes. Notes. Notes. Lecture 07 - Strings

Computer Language. It is a systematical code for communication between System and user. This is in two categories.

Reading Assignment. Strings. K.N. King Chapter 13. K.N. King Sections 23.4, Supplementary reading. Harbison & Steele Chapter 12, 13, 14

Advanced C Programming Topics

CS246 Spring14 Programming Paradigm Files, Pipes and Redirection

Input/Output: Advanced Concepts

C Syntax Arrays and Loops Math Strings Structures Pointers File I/O. Final Review CS Prof. Jonathan Ventura. Prof. Jonathan Ventura Final Review

LSN 3 C Concepts for OS Programming

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

CSci 4061 Introduction to Operating Systems. Input/Output: High-level

Fundamentals of Programming & Procedural Programming

Computer Science & Engineering 150A Problem Solving Using Computers

Kurt Schmidt. October 30, 2018

Quick review of previous lecture Ch6 Structure Ch7 I/O. EECS2031 Software Tools. C - Structures, Unions, Enums & Typedef (K&R Ch.

High Performance Programming Programming in C part 1

CSI 402 Lecture 2 Working with Files (Text and Binary)

Getting Started. Project 1

CS107 Spring 2019, Lecture 4 C Strings

Content. Input Output Devices File access Function of File I/O Redirection Command-line arguments

CSE 12 Spring 2016 Week One, Lecture Two

File Handling in C. EECS 2031 Fall October 27, 2014

C Basics And Concepts Input And Output

Transcription:

C mini reference Contents 1 Input/Output: stdio.h 2 1.1 int printf ( const char * format,... );......................... 2 1.2 int scanf ( const char * format,... );.......................... 2 1.3 char * fgets ( char * str, int num, FILE * stream );.................. 3 1. FILE * fopen ( const char * filename, const char * mode );............. 3 1.5 int fclose ( FILE * stream );................................. 1.6 int fseek ( FILE * stream, long int offset, int origin );.............. 1.7 Other I/O functions......................................... 1.7.1 size t fread ( void * ptr, size t size, size t count, FILE * stream );.. 1.7.2 int fgetc ( FILE * stream );.............................. 5 1.7.3 size t fwrite ( const void * ptr, size t size, size t count, FILE * stream );............................................... 5 1.7. int fputc ( int character, FILE * stream );................... 5 1.7.5 long int ftell ( FILE * stream );.......................... 5 2 String handling: string.h 5 2.1 char * strcpy ( char * destination, const char * source );............. 5 2.2 char * strcat ( char * destination, const char * source );............. 5 2.3 size t strlen ( const char * str );............................. 6 2. int strcmp ( const char * str1, const char * str2 );.................. 6 2.5 Other string functions........................................ 7 2.5.1 char * strncpy ( char * destination, const char * source, size t num );. 7 2.5.2 char * strncat ( char * destination, const char * source, size t num );. 7 2.5.3 void * memset ( void * ptr, int value, size t num );.............. 7 2.5. char * strtok ( char * str, const char * delimiters );............ 7 2.5.5 char * strstr ( const char *, const char * );................. 7 3 Memory handling: stdlib.h 8 3.1 void* malloc (size t size);................................... 8 3.2 void* calloc (size t num, size t size);........................... 8 3.3 void* realloc (void* ptr, size t size);.......................... 9 3. void free (void* ptr);...................................... 9 3.5 void qsort (void* base, size t num, size t size, int (*compar)(const void*,const void*));.......................... 10 Character handling: ctype.h 11.1 int isalnum ( int c );...................................... 11.2 int isalpha ( int c );...................................... 11.3 int isdigit ( int c );...................................... 11. int isprint ( int c );...................................... 11.5 int isspace ( int c );...................................... 11.6 int tolower ( int c );...................................... 11.7 int toupper ( int c );...................................... 11 5 Binary numbers 12 6 Command line 12 6.1 First things to do........................................... 12 6.2 Compiling your program....................................... 12 6.3 Running your program........................................ 12 6. Using valgrind to check for memory errors............................. 12 1

1 Input/Output: stdio.h 1.1 int printf ( const char * format,... ); format A format specifier follows this prototype: %[flags][width][.precision][length]specifier specifier Output Example d or i Signed decimal integer 392 u Unsigned decimal integer 7235 x Unsigned hexadecimal integer 7fa f Decimal floating point, lowercase 392.65 c Character a s String of characters sample On success, the total number of characters written is returned. 1.2 int scanf ( const char * format,... ); format A format specifier follows this prototype: %[*][width][length]specifier specifier Description Characters extracted i Integer Any number of digits, optionally preceded by a sign (+ or -). Decimal digits assumed by default (0-9), but a 0 prefix introduces octal digits (0-7), and 0x hexadecimal digits (0-f). Signed argument. d or u Decimal integer Any number of decimal digits (0-9), optionally preceded by a sign (+ or -). d is for a signed argument, and u for an unsigned. f Floating point number A series of decimal digits, optionally containing a decimal point, optionally preceeded by a sign (+ or -) and optionally followed by the e or E character and a decimal integer c Character The next character. If a width other than 1 is specified, the function reads exactly width characters and stores them in the successive locations of the array passed as argument. No null character is appended at the end. s String of characters Any number of non-whitespace characters, stopping at the first whitespace character found. A terminating null character is automatically added at the end of the stored sequence.... (additional arguments) Depending on the format string, the function may expect a sequence of additional arguments, each containing a pointer to allocated storage where the interpretation of the extracted characters is stored with the appropriate type. On success, the function returns the number of items of the argument list successfully filled. This count can match the expected number of items or be less (even zero) due to a matching failure, a reading error, or the reach of the end-of-file. 2

1.3 char * fgets ( char * str, int num, FILE * stream ); Reads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or the end-of-file is reached, whichever happens first. A newline character makes fgets stop reading, but it is considered a valid character by the function and included in the string copied to str. A terminating null character is automatically appended after the characters copied to str. str Pointer to an array of chars where the string read is copied. num Maximum number of characters to be copied into str (including the terminating null-character). stream Pointer to a FILE object that identifies an input stream. stdin can be used as argument to read from the standard input. On success, the function returns str. If the end-of-file is encountered while attempting to read a character, the eof indicator is set (feof). If this happens before any characters could be read, the pointer returned is a null pointer (and the contents of str remain unchanged). 1 / f g e t s example / 2 #i n c l u d e <s t d i o. h> 3 i n t main ( ) 5 { 6 FILE p F i l e ; 7 char mystring [ 1 0 0 ] ; 8 9 p F i l e = fopen ( m y f i l e. t x t, r ) ; 10 i f ( p F i l e == NULL) p e r r o r ( Error opening f i l e ) ; 11 e l s e { 12 i f ( f g e t s ( mystring, 100, p F i l e )!= NULL ) 13 puts ( mystring ) ; 1 f c l o s e ( p F i l e ) ; 15 } 16 r e t u r n 0 ; 17 } 1. FILE * fopen ( const char * filename, const char * mode ); Opens the file whose name is specified in the parameter filename and associates it with a stream that can be identified in future operations by the FILE pointer returned. filename C string containing the name of the file to be opened. mode r w read: Open file for input operations. The file must exist. write: Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file. 3

If the file is successfully opened, the function returns a pointer to a FILE object that can be used to identify the stream on future operations. Otherwise, a null pointer is returned. 1 / fopen example / 2 #i n c l u d e <s t d i o. h> 3 i n t main ( ) { 5 FILE p F i l e ; 6 p F i l e = fopen ( m y f i l e. t x t, w ) ; 7 i f ( p F i l e!=null) 8 { 9 f p u t s ( fopen example, p F i l e ) ; 10 f c l o s e ( p F i l e ) ; 11 } 12 r e t u r n 0 ; 13 } 1.5 int fclose ( FILE * stream ); Closes the file associated with the stream and disassociates it. stream Pointer to a FILE object that specifies the stream to be closed. 1.6 int fseek ( FILE * stream, long int offset, int origin ); Sets the position indicator associated with the stream to a new position. stream Pointer to a FILE object that identifies the stream. offset Text files: Either zero, or a value returned by ftell. origin Position used as reference for the offset. It is specified by one of the following constants defined in cstdio exclusively to be used as arguments for this function: SEEK SET Beginning of file SEEK CUR Current position of the file pointer SEEK END End of file * If successful, the function returns zero. Otherwise, it returns non-zero value. 1.7 Other I/O functions 1.7.1 size t fread ( void * ptr, size t size, size t count, FILE * stream ); Reads an array of count elements, each one with a size of size bytes, from the stream and stores them in the block of memory specified by ptr.

1.7.2 int fgetc ( FILE * stream ); Returns the character currently pointed by the internal file position indicator of the specified stream. The internal file position indicator is then advanced to the next character. 1.7.3 size t fwrite ( const void * ptr, size t size, size t count, FILE * stream ); Writes an array of count elements, each one with a size of size bytes, from the block of memory pointed by ptr to the current position in the stream. 1.7. int fputc ( int character, FILE * stream ); Writes a character to the stream and advances the position indicator. 1.7.5 long int ftell ( FILE * stream ); Returns the current value of the position indicator of the stream. 2 String handling: string.h 2.1 char * strcpy ( char * destination, const char * source ); Copies the C string pointed by source into the array pointed by destination, including the terminating null character (and stopping at that point). destination Pointer to the destination array where the content is to be copied. source C string to be copied. destination is returned. 1 / s t r c p y example / 2 #i n c l u d e <s t d i o. h> 3 #i n c l u d e <s t r i n g. h> 5 i n t main ( ) 6 { 7 char s t r 1 []= Sample s t r i n g ; 8 char s t r 2 [ 0 ] ; 9 s t r c p y ( s t r 2, s t r 1 ) ; 10 r e t u r n 0 ; 11 } 2.2 char * strcat ( char * destination, const char * source ); Appends a copy of the source string to the destination string. The terminating null character in destination is overwritten by the first character of source, and a null-character is included at the end of the new string formed by the concatenation of both in destination. 5

destination Pointer to the destination array, which should contain a C string, and be large enough to contain the concatenated resulting string. source C string to be appended. This should not overlap destination. destination is returned. 1 / s t r c a t example / 2 #i n c l u d e <s t d i o. h> 3 #i n c l u d e <s t r i n g. h> 5 i n t main ( ) 6 { 7 char s t r [ 8 0 ] ; 8 s t r c p y ( s t r, t h e s e ) ; 9 s t r c a t ( s t r, s t r i n g s ) ; 10 s t r c a t ( s t r, are ) ; 11 s t r c a t ( s t r, concatenated. ) ; 12 puts ( s t r ) ; 13 r e t u r n 0 ; 1 } 2.3 size t strlen ( const char * str ); Returns the length of the C string str. The length of a C string is determined by the terminating null-character: A C string is as long as the number of characters between the beginning of the string and the terminating null character (without including the terminating null character itself). str C string. The length of string. 2. int strcmp ( const char * str1, const char * str2 ); Compares the C string str1 to the C string str2. str1 C string to be compared. str2 C string to be compared. 6

Returns an integral value indicating the relationship between the strings: >0 the first character that does not match has a lower value in ptr1 than in ptr2 0 the contents of both strings are equal <0 the first character that does not match has a greater value in ptr1 than in ptr2 1 / strcmp example / 2 #i n c l u d e <s t d i o. h> 3 #i n c l u d e <s t r i n g. h> 5 i n t main ( ) 6 { 7 char key [ ] = apple ; 8 char b u f f e r [ 8 0 ] ; 9 do { 10 p r i n t f ( Guess my f a v o r i t e f r u i t? ) ; 11 f f l u s h ( stdout ) ; 12 s c a n f ( %79s, b u f f e r ) ; 13 } w h i l e ( strcmp ( key, b u f f e r )!= 0) ; 1 puts ( Correct answer! ) ; 15 r e t u r n 0 ; 16 } 2.5 Other string functions 2.5.1 char * strncpy ( char * destination, const char * source, size t num ); Copies the first num characters of source to destination. If the end of the source C string (which is signaled by a null-character) is found before num characters have been copied, destination is padded with zeros until a total of num characters have been written to it. 2.5.2 char * strncat ( char * destination, const char * source, size t num ); Appends the first num characters of source to destination, plus a terminating null-character. If the length of the C string in source is less than num, only the content up to the terminating null-character is copied. 2.5.3 void * memset ( void * ptr, int value, size t num ); Sets the first num bytes of the block of memory pointed by ptr to the specified value (interpreted as an unsigned char). 2.5. char * strtok ( char * str, const char * delimiters ); A sequence of calls to this function split str into tokens, which are sequences of contiguous characters separated by any of the characters that are part of delimiters. On a first call, the function expects a C string as argument for str, whose first character is used as the starting location to scan for tokens. In subsequent calls, the function expects a null pointer and uses the position right after the end of the last token as the new starting location for scanning. 2.5.5 char * strstr ( const char *, const char * ); Returns a pointer to the first occurrence of str2 in str1, or a null pointer if str2 is not part of str1. 7

3 Memory handling: stdlib.h 3.1 void* malloc (size t size); Allocates a block of size bytes of memory, returning a pointer to the beginning of the block. The content of the newly allocated block of memory is not initialized, remaining with indeterminate values. size Size of the memory block, in bytes. On success, a pointer to the memory block allocated by the function. 1 / malloc example : random s t r i n g g e n e r a t o r / 2 #i n c l u d e <s t d i o. h> / p r i n t f, scanf, NULL / 3 #i n c l u d e <s t d l i b. h> / malloc, f r e e, rand / 5 i n t main ( ) 6 { 7 i n t i, n ; 8 char b u f f e r ; 9 10 p r i n t f ( How long do you want the s t r i n g? ) ; 11 s c a n f ( %d, &i ) ; 12 13 b u f f e r = malloc ( i +1) ; 1 i f ( b u f f e r==null) e x i t ( 1 ) ; 15 16 f o r ( n=0; n<i ; n++) 17 b u f f e r [ n]= rand ( )%26+ a ; 18 b u f f e r [ i ]= \0 ; 19 20 p r i n t f ( Random s t r i n g : %s \n, b u f f e r ) ; 21 f r e e ( b u f f e r ) ; 22 23 r e t u r n 0 ; 2 } 3.2 void* calloc (size t num, size t size); Allocates a block of memory for an array of num elements, each of them size bytes long, and initializes all its bits to zero. The effective result is the allocation of a zero-initialized memory block of (num*size) bytes. num Number of elements to allocate. size Size of each element. On success, a pointer to the memory block allocated by the function. 8

3.3 void* realloc (void* ptr, size t size); Changes the size of the memory block pointed to by ptr. The function may move the memory block to a new location (whose address is returned by the function). The content of the memory block is preserved up to the lesser of the new and old sizes, even if the block is moved to a new location. If the new size is larger, the value of the newly allocated portion is indeterminate. In case that ptr is a null pointer, the function behaves like malloc, assigning a new block of size bytes and returning a pointer to its beginning. ptr Pointer to a memory block previously allocated with malloc, calloc or realloc. Alternatively, this can be a null pointer, in which case a new block is allocated (as if malloc was called). size New size for the memory block, in bytes. A pointer to the reallocated memory block, which may be either the same as ptr or a new location. 1 / r e a l l o c example : rememb o matic / 2 #i n c l u d e <s t d i o. h> / p r i n t f, scanf, puts / 3 #i n c l u d e <s t d l i b. h> / r e a l l o c, f r e e, e x i t, NULL / 5 i n t main ( ) 6 { 7 i n t input, n ; 8 i n t count = 0 ; 9 i n t numbers = NULL; 10 i n t more numbers = NULL; 11 12 do { 13 p r i n t f ( Enter an i n t e g e r value (0 to end ) : ) ; 1 s c a n f ( %d, &input ) ; 15 count++; 16 17 more numbers = r e a l l o c ( numbers, count s i z e o f ( i n t ) ) ; 18 19 i f ( more numbers!=null) { 20 numbers=more numbers ; 21 numbers [ count 1]= input ; 22 } 23 e l s e { 2 f r e e ( numbers ) ; 25 puts ( Error ( r e ) a l l o c a t i n g memory ) ; 26 e x i t ( 1 ) ; 27 } 28 } w h i l e ( input!=0) ; 29 30 p r i n t f ( Numbers e n t e r e d : ) ; 31 f o r ( n=0;n<count ; n++) p r i n t f ( %d, numbers [ n ] ) ; 32 f r e e ( numbers ) ; 33 3 r e t u r n 0 ; 35 } 3. void free (void* ptr); A block of memory previously allocated by a call to malloc, calloc or realloc is deallocated, making it available again for further allocations. 9

3.5 void qsort (void* base, size t num, size t size, int (*compar)(const void*,const void*)); Sorts the num elements of the array pointed to by base, each element size bytes long, using the compar function to determine the order. The sorting algorithm used by this function compares pairs of elements by calling the specified compar function with pointers to them as argument. The function does not return any value, but modifies the content of the array pointed to by base reordering its elements as defined by compar. base Pointer to the first object of the array to be sorted, converted to a void*. num Number of elements in the array pointed to by base. size Size in bytes of each element in the array. compar Pointer to a function that compares two elements. This function is called repeatedly by qsort to compare two elements. It shall follow the following prototype: int compar (const void* p1, const void* p2); Taking two pointers as arguments (both converted to const void*). The function defines the order of the elements by returning (in a stable and transitive manner): >0 The element pointed to by p1 goes after the element pointed to by p2 0 The element pointed to by p1 is equivalent to the element pointed to by p2 <0 The element pointed to by p1 goes before the element pointed to by p2 For types that can be compared using regular relational operators, a general compar function may look like: 1 i n t comparemytype ( c o n s t void a, c o n s t void b ) 2 { 3 i f ( (MyType ) a < (MyType ) b ) r e t u r n 1; i f ( (MyType ) a == (MyType ) b ) r e t u r n 0 ; 5 i f ( (MyType ) a > (MyType ) b ) r e t u r n 1 ; 6 } 1 / q s o r t example / 2 #i n c l u d e <s t d i o. h> / p r i n t f / 3 #i n c l u d e <s t d l i b. h> / q s o r t / 5 i n t v a l u e s [ ] = { 0, 10, 100, 90, 20, 25 } ; 6 7 i n t compare ( c o n s t void a, c o n s t void b ) 8 { 9 r e t u r n ( ( i n t ) a ( i n t ) b ) ; 10 } 11 12 i n t main ( ) 13 { 1 i n t n ; 15 q s o r t ( values, 6, s i z e o f ( i n t ), compare ) ; 16 f o r ( n=0; n<6; n++) 17 p r i n t f ( %d, v a l u e s [ n ] ) ; 18 r e t u r n 0 ; 19 } 10

Character handling: ctype.h Parameter for all functions below: Character to be converted, casted to an int, or EOF. Return value for all is-functions: A value different from zero (i.e., true) if indeed c is an alphabetic letter. Zero (i.e., false) otherwise..1 int isalnum ( int c ); Checks whether c is either a decimal digit or an uppercase or lowercase letter..2 int isalpha ( int c ); Checks whether c is an alphabetic letter..3 int isdigit ( int c ); Checks whether c is a decimal digit character.. int isprint ( int c ); Checks whether c is a printable character..5 int isspace ( int c ); Checks whether c is a white-space character..6 int tolower ( int c ); Converts c to its lowercase equivalent if c is an uppercase letter and has a lowercase equivalent. If no such conversion is possible, the value returned is c unchanged. The lowercase equivalent to c, if such value exists, or c (unchanged) otherwise..7 int toupper ( int c ); Converts c to its uppercase equivalent if c is a lowercase letter and has an uppercase equivalent. If no such conversion is possible, the value returned is c unchanged. The uppercase equivalent to c, if such value exists, or c (unchanged) otherwise. 11

5 Binary numbers Decimal pattern Hexadecimal pattern Binary pattern 0 0x0 0 1 0x1 1 2 0x2 10 3 0x3 11 0x 100 5 0x5 101 6 0x6 110 7 0x7 111 8 0x8 1000 9 0x9 1001 10 0xA 1010 11 0xB 1011 12 0xC 1100 13 0xD 1101 1 0xE 1110 15 0xF 1111 6 Command line 6.1 First things to do Start command line, application named Terminal in Ubuntu. The folder that the command line opens by default is your home folder. Navigate to the correct folder (that has your code) with command cd (change directory). If you saved your code to your home directory, you do not need to use cd. You can get up one directory by using command cd.. and to your home directory with cd. 6.2 Compiling your program For compiling we use a tool called gcc. The parameters for gcc that are used when grading your program are -Wvla -Wall -g -std=c99. If you have for example two.c-files called main.c and program.c you would compile them to a executable file called program by the following command: gcc -Wvla -Wall -g -std=c99 -o program program.c main.c 6.3 Running your program After compiling successfully you could now run your program with command:./program 6. Using valgrind to check for memory errors To see that your program doesn t have any memory errors, run it under valgrind with the following command: valgrind --leak-check=full --track-origins=yes./program If you got ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0), then everything is fine, otherwise please check the output from valgrind to fix problems. 12