# #include <stdio.h> #include <stdlib.h> #include <math.h> /* Argument dimension n and image dimension q <= 8 */ /* Increase if needed.

Save this PDF as:

Size: px
Start display at page:

Download "#include <stdio.h> #include <stdlib.h> #include <math.h> /* Argument dimension n and image dimension q <= 8 */ /* Increase if needed."

## Transcription

1 B Quellcode /*** bma.c ********************************************************/ /* Analysis of Boolean Maps (S-Boxes) V 0.4 */ /* Klaus Pommerening */ /* Institut fuer Medizinische Biometrie, Epidemilogie und */ /* Informatik */ /* Johannes-Gutenberg-Universitaet */ /* D Mainz */ /* */ /* 21 August last change 15 September 2001 */ /* Send bug reports and comments by . */ /******************************************************************/ /* Copyright by the author. */ /* The use of this program code is free for private and */ /* educational use. */ /* Usual disclaimers apply. */ /******************************************************************/ /* Usage: bma <input >output */ /* [I. e. use input and output redirection] */ /* Input from stdin: Matrix of coefficients of a boolean map in */ /* Algebraic Normal Form (ANF) -- */ /* one line per component function. */ /* Let K = Galois Field with 2 elements. */ /* A map f: K^n ---> K^q is given by q components, */ /* each component given by 2^n coefficients in ANF. */ /* [Input in lines instead of columns for convenience.] */ /* Output to stdout: */ /* 1. ANF -- one column per component function */ /* 2. Truth table (one column per component function) */ /* 3. Characteristic function as a 2^n x 2^q matrix */ /* 4. Walsh transform of characteristic function as a 2^n x 2^q */ /* matrix */ /* 5. Linear profile */ /* 6. Differential profile */ /* 7. Linearity/nonlinearity measures: */ /* linear potential, differential potential, nonlinearity */ /* The bit string (b_1,..., b_n) is identified with the integer */ /* b_1 2^n b_n 2^0. */ /******************************************************************/ 114

2 #include <stdio.h> #include <stdlib.h> #include <math.h> /* Argument dimension n and image dimension q <= 8 */ /* Increase if needed. The program will allocate 5 arrays of */ /* length up to MAXLEN*MAXLEN = 2^2*MAXDIM. */ /* MAXLEN must be 2^MAXDIM. */ #define MAXDIM 8 #define MAXLEN

3 /* getinput: Read component coefficients x from stdin. */ /* Set dimension dim1 of argument space and */ /* dimension dim2 of image space. */ /* (dim1 = base 2 log of input line length, */ /* dim2 = number of input lines.) */ /* Memory for x is allocated inside. */ /* Return codes: */ /* 0 = Input o. K. */ /* 1 = dim1 or dim2 exceeds MAXDIM. */ /* 2 = Input line has wrong length. */ /* 3 = Input contains value!= 0 or 1. */ int getinput(unsigned ***x, unsigned *dim1, unsigned *dim2) unsigned i, n; /* Dimension */ unsigned long m, k, j; /* Length */ char buf[maxlen+2]; char *bufptr; i = 0; n = 0; /* 257 = MAXLENGTH + 1 */ while ((scanf("%257s", buf)!= EOF) & (i <= MAXDIM)) if (i == MAXDIM) fprintf(stderr, "bma.getinput: Too many lines.\n"); return 1; m = strlen(buf); if (m > MAXLEN) fprintf(stderr, "bma.getinput: Line too long.\n"); return 2; if (i == 0) /* First line */ while (m > 1) /* Calculate dim1 and 2^dim1 */ k = m >> 1; if ((k << 1)!= m) /* m not a power of 2 */ fprintf(stderr, "bma.getinput: Line length not a power of 2.\n"); return 2; n++; m = k; /* Now n = dim1 */ *dim1 = n; (*x) = (unsigned **) malloc(maxdim * sizeof(unsigned *)); k = 1 << n; /* Line length 2^n */ else /* Follow-up lines */ 116

4 if (m!= k) fprintf(stderr, "bma.getinput: Line lengths differ.\n"); return 2; /* Now buf contains a line of good length */ (*x)[i] = (unsigned *) malloc(k * sizeof(unsigned)); bufptr = buf; /* Cursor pointer into buf */ for (j = 0; j < k; j++) sscanf(bufptr, "%1u", &((*x)[i][j])); if ((*x)[i][j] > 1) fprintf(stderr, "bma.getinput: Input not in range.\n"); return 3; bufptr++; i++; /* end while */ *dim2 = i; return 0; 117

5 /* rev: Recursive Evaluation of a Boolean function f */ /* Input: Array x of coefficients of Algebraic NF */ /* Output: Truth table y of f */ /* There is no error handling. The input is assumed to be correct.*/ void rev(unsigned *x, unsigned *y, unsigned dim) unsigned z[maxlen]; unsigned long m, k, mi; unsigned n, i; n = dim; m = 1 << n; /* length of array */ for (k = 0; k < m; k++) y[k] = x[k]; mi = 1; for (i = 0; i < n; i++) for (k = 0; k < m; k++) if ((k >> i) % 2) z[k] = y[k-mi] ^ y[k]; else z[k] = y[k]; for (k = 0; k < m; k++) y[k] = z[k]; mi *= 2; return; 118

6 /* wt: Walsh transform of an integer valued function phi on K^dim */ /* Input: Array of values of phi */ /* Output: Array of values of Walsh transform */ /* There is no error handling. The input is assumed to be correct.*/ void wt(long *x, long *y, unsigned dim) long z[maxlen*maxlen]; unsigned long m, k, mi; unsigned n, i; n = dim; m = 1 << n; /* Length of truth table */ for (k = 0; k < m; k++) y[k] = x[k]; mi = 1; for (i = 0; i < n; i++) for (k = 0; k < m; k++) if ((k >> i) % 2) z[k] = y[k-mi] - y[k]; else z[k] = y[k] + y[k+mi]; for (k = 0; k < m; k++) y[k] = z[k]; mi *= 2; return; 119

7 /* printbin: Print the w lowest bits of the number k to stdout. */ /* There is no error handling. The input is assumed to be correct.*/ void printbin(unsigned w, unsigned long k) unsigned i, b[maxdim]; unsigned long p, x; p = 1; for (i = 0; i < w; i++) x = k&p; if (x) b[w-i] = 1; else b[w-i] = 0; p = p*2; for (i = 1; i <= w; i++) printf("%1d", b[i]); 120

8 /* reduce: Divide the input vector x of length lt by the highest */ /* possible power 2^r of 2. */ /* Return value: The exponent r. */ /* There is no error handling. The input is assumed to be correct.*/ int reduce(long *x, unsigned long lt) unsigned long i = 0, j; long z; unsigned r = 0; while (x[i] == 0) i++; if (i == lt) return 0; /* All components of x were 0. */ /* Now x[i]!= */ z = x[i]; /* Calculate start value for r */ while (!(z%2)) /* z is even */ z = z >> 1; r++; /* Now r = max exponent with 2^r x[i] */ if (r == 0) return 0; /* No sense in continuing */ for (j = i+1; j < lt; j++) z = x[j]; if (((z>>r)<<r)!= z) /* Else r unchanged */ r = 0; /* Calculate new value for r */ while (!(z%2)) z = z >> 1; r++; if (r == 0) return 0; /* Now r = max exponent with 2^r x[i],..., x[lt-1] */ /* and r > */ for (j = 0; j < lt; j++) x[j] = x[j] >> r; return r; 121

9 /* max: Calculate the maximum entry of the input vector x */ /* between indices start and end-1, that is, */ /* max(x[start], x[end-1]). */ /* There is almost no error handling. */ /* If end <= start, the function returns 0. */ /* Otherwise the input is assumed to be correct. */ long max(long *x, unsigned long start, unsigned long end) long mm; unsigned long i; if (end <= start) return 0; mm = x[start]; for (i = start+1; i < end; i++) if (x[i] > mm) mm = x[i]; return mm; 122

10 /* prttabl0: Print a 2^n x q matrix. */ /* There is no error handling. The input is assumed to be correct.*/ void prttabl0(unsigned **x, unsigned dim1, unsigned dim2) unsigned long length1, length2, k, l; unsigned i; length1 = 1 << dim1; length2 = dim2; for (i = 0; i <= dim1; i++) printf(" "); /* Table header... */ for (l = 1; l <= length2; l++) printf("%2d", l); /*... */ for (i = 0; i <= dim1; i++) printf(" "); /*... */ for (l = 0; l < length2; l++) printf("--"); /*... */ for (k = 0; k < length1; k++) /* Print length1 lines: */ printbin(dim1,k); /* line header... */ printf(" "); /*... */ for (l = 0; l < dim2; l++) printf(" %d", x[l][k]); 123

11 /* prttabl1: Print a 2^n x 2^q matrix. */ /* There is no error handling. The input is assumed to be correct.*/ void prttabl1(long *x, unsigned dim1, unsigned dim2) unsigned long length1, length2, k, l; unsigned i; length1 = 1 << dim1; length2 = 1 << dim2; for (i = 0; i <= dim1; i++) printf(" "); /* Table header... */ for (l = 0; l < length2; l++) printf(" "); /*... */ printbin(dim2,l); /*... */ /*... */ for (i = 0; i <= dim1; i++) printf(" "); /*... */ for (l = 0; l < length2*dim2+length2; l++) printf("-"); /*... */ for (k = 0; k < length1; k++) /* Print length1 lines: */ printbin(dim1,k); /* line header... */ printf(" "); /*... */ for (l = 0; l < length2; l++) if (dim2 > 2) for (i = 0; i < dim2-2; i++) printf(" "); if (dim2 == 1) printf("%2d", x[(k<<dim2)+l]); else printf("%3d", x[(k<<dim2)+l]); 124

12 /******************************************************************/ int main() unsigned **a = NULL; /* Array of coefficients */ unsigned **f = NULL; /* Array of values (truth tbl) */ /* Note that a and f have their components arranged in rows - */ /* that s convenient for input and for calling rev on */ /* the component functions. */ long *g = NULL; /* Characteristic function */ long *c = NULL; /* Walsh spectrum */ long *lp = NULL; /* Linear profile */ long *dp = NULL; /* Differential profile */ unsigned n, q, i, j, n2; unsigned long m, p, k, l, y; int rc; long ll, dd, nl, maxnl; double la; /* Step 1: Algebraic Normal Form */ rc = getinput(&a, &n, &q); if (rc) exit(1); printf("argument Dimension = %d\n", n); m = 1 << n; /* Argument space has m elements */ printf("argument space has %d elements.\n", m); printf("image Dimension = %d\n", q); p = 1 << q; /* Image space has p elements */ printf("image space has %d elements.\n", p); printf("1. Algebraic Normal Form:\n"); printf("[columns = Image components]\n\n"); prttabl0(a, n, q); /* Step 2: Truth Table */ f = (unsigned **) malloc(q * sizeof(unsigned *)); for (i = 0; i < q; i++) f[i] = (unsigned *) malloc(m * sizeof(unsigned)); rev(a[i], f[i], n); /* calculate truth table */ printf("2. Truth Table:\n"); printf("[columns = Image components]\n\n"); prttabl0(f, n, q); 125

13 /* Step 3: Characteristic Function */ g = (long *) malloc(m * p * sizeof(long)); for (k = 0; k < m; k++) /* One line of values */ for (l = 0; l < p; l++) g[(k<<q)+l] = 0; /* Set default value */ y = 0; /* Calculate value of map at k */ for (i = 0; i < q; i++) y = y + (f[q-1-i][k] << i); g[(k<<q)+y] = 1; /* Here charact. function is 1. */ printf("3. Characteristic Function:\n"); prttabl1(g, n, q); /* Step 4: Walsh Spectrum */ c = (long *) malloc(m * p * sizeof(long)); wt(g, c, n+q); /* calculate Walsh transform */ printf("4. Walsh Spectrum:\n"); prttabl1(c, n, q); /* Step 5: Linear Profile */ lp = (long *) malloc(m * p * sizeof(long)); for (k = 0; k < m*p; k++) lp[k] = c[k]*c[k]; rc = reduce(lp, m*p); printf("5. Linear Profile:\n"); printf("[to normalize divide by %d]\n", lp[0]); prttabl1(lp, n, q); /* Step 6: Differential Profile */ dp = (long *) malloc(m * p * sizeof(long)); wt(lp, dp, n+q); rc = reduce(dp, m*p); printf("6. Differential Profile:\n"); printf("[to normalize divide by %d]\n", dp[0]); prttabl1(dp, n, q); 126

14 /* Step 7: Linearity/nonlinearity measures */ ll = max(lp, 1, m*p); /* Numerator of linear potential */ /* Denominator is lp[0]. */ dd = max(dp, 1, m*p); /* Numerator of differential potential */ /* Denominator is dp[0]. */ la = (double) ll; la = la/lp[0]; la = 1 - sqrt(la); la = la * (m >> 1); nl = floor(la + 0.5); /* Nonlinearity */ maxnl = m >> 1; if (n <= 1) maxnl = 0; else if (!(n%2)) /* n is even */ n2 = (n >> 1) - 1; maxnl = maxnl - (1 << n2); else /* n is odd >=3 */ la = 1 << (n-2); la = sqrt(la); maxnl = floor(maxnl - la); printf("7. Linearity/nonlinearity measures:\n"); printf("linear potential: %d/%d\n", ll, lp[0]); printf(" [Higher values mean more linearity.]\n"); printf(" [Theoretical minimum = 1/%d maximum = 1]\n", m); printf("differential potential: %d/%d\n", dd, dp[0]); printf(" [Higher values mean more linearity.]\n"); printf(" [Theoretical minimum = 1/%d maximum = 1]\n", p); printf("nonlinearity: %d\n", nl); printf(" [Lower values mean more linearity.]\n"); printf(" [Theoretical minimum = 0 maximum = %d]\n", maxnl); /* Finish **********************************************************/ exit(0); 127

### CS 0449 Sample Midterm

Name: CS 0449 Sample Midterm Multiple Choice 1.) Given char *a = Hello ; char *b = World;, which of the following would result in an error? A) strlen(a) B) strcpy(a, b) C) strcmp(a, b) D) strstr(a, b)

### C: How to Program. Week /Apr/23

C: How to Program Week 9 2007/Apr/23 1 Review of Chapters 1~5 Chapter 1: Basic Concepts on Computer and Programming Chapter 2: printf and scanf (Relational Operators) keywords Chapter 3: if (if else )

### File IO and command line input CSE 2451

File IO and command line input CSE 2451 File functions Open/Close files fopen() open a stream for a file fclose() closes a stream One character at a time: fgetc() similar to getchar() fputc() similar to

### Outline Arrays Examples of array usage Passing arrays to functions 2D arrays Strings Searching arrays Next Time. C Arrays.

CS 2060 Week 5 1 Arrays Arrays Initializing arrays 2 Examples of array usage 3 Passing arrays to functions 4 2D arrays 2D arrays 5 Strings Using character arrays to store and manipulate strings 6 Searching

### Slide Set 8. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Slide Set 8 for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary October 2017 ENCM 339 Fall 2017 Section 01 Slide

### School of Computer Science Introduction to Algorithms and Programming Winter Midterm Examination # 1 Wednesday, February 11, 2015

Page 1 of 8 School of Computer Science 60-141-01 Introduction to Algorithms and Programming Winter 2015 Midterm Examination # 1 Wednesday, February 11, 2015 Marking Exemplar Duration of examination: 75

### Algorithms & Programming. Midterm Examination # 2. Student Name: Student ID Number: Duration of examination:

School of Computer Science 60-141-01 Algorithms & Programming Winter 2007 Midterm Examination # 2 Wednesday, March 21, 2007 Student Name: First Name Family Name Student ID Number: Duration of examination:

### ECE264 Fall 2013 Exam 3, November 20, 2013

ECE264 Fall 2013 Exam 3, November 20, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.

### Structures. Basics of Structures (6.1) EECS l Now struct point is a valid type. l Defining struct variables: struct point { int x; int y; };

Structures EECS 2031 25 September 2017 1 Basics of Structures (6.1) struct point { int x; int y; keyword struct introduces a structure declaration. point: structure tag x, y: members The same member names

### sends the formatted data to the standard output stream (stdout) int printf ( format_string, argument_1, argument_2,... ) ;

INPUT AND OUTPUT IN C Function: printf() library: sends the formatted data to the standard output stream (stdout) int printf ( format_string, argument_1, argument_2,... ) ; format_string it is

### ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty.

ECE 264 Exam 2 6:30-7:30PM, March 9, 2011 I certify that I will not receive nor provide aid to any other student for this exam. Signature: You must sign here. Otherwise you will receive a 1-point penalty.

### Content. In this chapter, you will learn:

ARRAYS & HEAP Content In this chapter, you will learn: To introduce the array data structure To understand the use of arrays To understand how to define an array, initialize an array and refer to individual

### The C Programming Language Part 2. (with material from Dr. Bin Ren, William & Mary Computer Science)

The C Programming Language Part 2 (with material from Dr. Bin Ren, William & Mary Computer Science) 1 Overview Input/Output Structures and Arrays 2 Basic I/O character-based putchar (c) output getchar

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

CSI 402 Lecture 2 Working with Files (Text and Binary) 1 / 30 AQuickReviewofStandardI/O Recall that #include allows use of printf and scanf functions Example: int i; scanf("%d", &i); printf("value

### 1/25/2018. ECE 220: Computer Systems & Programming. Write Output Using printf. Use Backslash to Include Special ASCII Characters

University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 220: Computer Systems & Programming Review: Basic I/O in C Allowing Input from the Keyboard, Output to the Monitor

### CSC209H Lecture 3. Dan Zingaro. January 21, 2015

CSC209H Lecture 3 Dan Zingaro January 21, 2015 Streams (King 22.1) Stream: source of input or destination for output We access a stream through a file pointer (FILE *) Three streams are available without

### C introduction: part 1

What is C? C is a compiled language that gives the programmer maximum control and efficiency 1. 1 https://computer.howstuffworks.com/c1.htm 2 / 26 3 / 26 Outline Basic file structure Main function Compilation

### CS240: Programming in C

CS240: Programming in C Lecture 13 si 14: Unix interface for working with files. Cristina Nita-Rotaru Lecture 13/Fall 2013 1 Working with Files (I/O) File system: specifies how the information is organized

### CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

CS 261 Fall 2017 Mike Lam, Professor C Introduction Variables, Memory Model, Pointers, and Debugging The C Language Systems language originally developed for Unix Imperative, compiled language with static

### ECE264 Summer 2013 Exam 1, June 20, 2013

ECE26 Summer 2013 Exam 1, June 20, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it. I

### COP 3223 Introduction to Programming with C - Study Union - Fall 2017

COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................

### C: How to Program. Week /Mar/05

1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

### THE FUNDAMENTAL DATA TYPES

THE FUNDAMENTAL DATA TYPES Declarations, Expressions, and Assignments Variables and constants are the objects that a prog. manipulates. All variables must be declared before they can be used. #include

### ECE264 Fall 2013 Exam 1, September 24, 2013

ECE264 Fall 2013 Exam 1, September 24, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.

### Introduction to C. Systems Programming Concepts

Introduction to C Systems Programming Concepts Introduction to C A simple C Program Variable Declarations printf ( ) Compiling and Running a C Program Sizeof Program #include What is True in C? if example

### AE52/AC52/AT52 C & Data Structures JUNE 2014

Q.2 a. Write a program to add two numbers using a temporary variable. #include #include int main () int num1, num2; clrscr (); printf( \n Enter the first number : ); scanf ( %d, &num1);

### Input/output functions

Computer Programming Input/output functions Marius Minea marius@cs.upt.ro 6 November 2017 All inputs must be checked! A program will not always receive the data it asks for User may make mistakes, or may

### Fundamentals of Programming

Fundamentals of Programming Lecture 4 Input & Output Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline printf scanf putchar getchar getch getche Input and Output in

### Fundamentals of Programming

Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

### Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

### 1/31/2018. Overview. The C Programming Language Part 2. Basic I/O. Basic I/O. Basic I/O. Conversion Characters. Input/Output Structures and Arrays

Overview The C Programming Language Part 2 Input/Output Structures and Arrays (with material from Dr. Bin Ren, William & Mary Computer Science) 1 2 character-based putchar (c) output getchar () input formatted

### #3. (Recursion) Write a recursive function to compute f(x) = f(x - 1) + f(x - 2) with f(0) = 0 and f(1) = 1.

EGN 3210 Sample Test 2 Dr. Fernando Gonzalez NAME S.S.# #1. (Functions) Write a function that receives 3 integers, and returns the value of the largest one through the function name. #2. (Functions) What

### Friday, September 16, Lab Notes. Command line arguments More pre-processor options Programs: Finish Program 1, begin Program 2 due next week

Friday, September 16, 2016 Lab Notes Topics for today Redirection of input and output Command line arguments More pre-processor options Programs: Finish Program 1, begin Program 2 due next week 1. Redirection

### AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University

AN OVERVIEW OF C, PART 3 CSE 130: Introduction to Programming in C Stony Brook University FANCIER OUTPUT FORMATTING Recall that you can insert a text field width value into a printf() format specifier:

### C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 2 (Minor modifications by the instructor) 1 Scope Rules A variable declared inside a function is a local variable Each local variable in a function comes into existence when the function

### Question 1. Part (a) [2 marks] error: assignment of read-only variable x ( x = 20 tries to modify a constant) Part (b) [1 mark]

Note to Students: This file contains sample solutions to the term test together with the marking scheme and comments for each question. Please read the solutions and the marking schemes and comments carefully.

### BİL200 TUTORIAL-EXERCISES Objective:

Objective: The purpose of this tutorial is learning the usage of -preprocessors -header files -printf(), scanf(), gets() functions -logic operators and conditional cases A preprocessor is a program that

### I/O Management! Goals of this Lecture!

I/O Management! 1 Goals of this Lecture! Help you to learn about:" The Unix stream concept" Standard C I/O functions" Unix system-level functions for I/O" How the standard C I/O functions use the Unix

1 Chapter 6 Arrays Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Chapter 6 - Arrays 6.1 Introduction 6.2 Arrays 6.3 Declaring Arrays 6.4 Examples Using Arrays

### A Short Course for REU Students Summer Instructor: Ben Ransford

C A Short Course for REU Students Summer 2008 Instructor: Ben Ransford http://www.cs.umass.edu/~ransford/ ransford@cs.umass.edu 1 Outline Today: basic syntax, compilation Next time: pointers, I/O, libraries

### CS 465 Networks. Client / Server Assignment. School of Computer Science Howard Hughes College of Engineering University of Nevada, Las Vegas

CS 465 Networks Client / Server Assignment School of Computer Science Howard Hughes College of Engineering University of Nevada, Las Vegas (c) Matt Pedersen, 2006 1 Client/Server Setup In this assignment

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

File Handling in C EECS 2031 Fall 2014 October 27, 2014 1 Reading from and writing to files in C l stdio.h contains several functions that allow us to read from and write to files l Their names typically

### int marks[10]; // fixed size and fixed address No change in Memory address.

Dynamic Memory Allocation : Used When we want to allocate memory during run time. int marks[10]; // fixed size and fixed address No change in Memory address. // fixed size. ( no change in size possible

### Example: Pointer Basics

Example: Pointer Basics #include int (void) { float a1, a2; /* Simple variables */ float *p1, *p2, *w; /* Pointers to variables of type float */ a1 = 10.0, a2 = 20.0; printf("after a1 = 10.0;

### Functions. Systems Programming Concepts

Functions Systems Programming Concepts Functions Simple Function Example Function Prototype and Declaration Math Library Functions Function Definition Header Files Random Number Generator Call by Value

### CSC 1107: Structured Programming

CSC 1107: Structured Programming J. Kizito Makerere University e-mail: www: materials: e-learning environment: office: jkizito@cis.mak.ac.ug http://serval.ug/~jona http://serval.ug/~jona/materials/csc1107

### University of California San Diego Department of Electrical and Computer Engineering. ECE 15 Final Exam

University of California San Diego Department of Electrical and Computer Engineering ECE 15 Final Exam Tuesday, March 21, 2017 3:00 p.m. 6:00 p.m. Room 109, Pepper Canyon Hall Name Class Account: ee15w

### Recitation 2/18/2012

15-213 Recitation 2/18/2012 Announcements Buflab due tomorrow Cachelab out tomorrow Any questions? Outline Cachelab preview Useful C functions for cachelab Cachelab Part 1: you have to create a cache simulator

### Understanding Pointers

Division of Mathematics and Computer Science Maryville College Pointers and Addresses Memory is organized into a big array. Every data item occupies one or more cells. A pointer stores an address. A pointer

### Arrays and Pointers (part 2) Be extra careful with pointers!

Arrays and Pointers (part 2) EECS 2031 22 October 2017 1 Be extra careful with pointers! Common errors: l Overruns and underruns Occurs when you reference a memory beyond what you allocated. l Uninitialized

### LESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long

LESSON 5 ARITHMETIC DATA PROCESSING The arithmetic data types are the fundamental data types of the C language. They are called "arithmetic" because operations such as addition and multiplication can be

### Writing to and reading from files

Writing to and reading from files printf() and scanf() are actually short-hand versions of more comprehensive functions, fprintf() and fscanf(). The difference is that fprintf() includes a file pointer

### Today's Topics. CISC 458 Winter J.R. Cordy

Today's Topics Last Time Semantics - the meaning of program structures Stack model of expression evaluation, the Expression Stack (ES) Stack model of automatic storage, the Run Stack (RS) Today Managing

### Basic C Program: Print to stdout. Basic C Program. Basic C Program: Print to stdout. Header Files. Read argument and print. Read argument and print

CSC 4304 - Systems Programming Fall 2010 Lecture - II Basics of C Programming Summary of Last Class Basics of UNIX: logging in, changing password text editing with vi, emacs and pico file and directory

### Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Introduction to C Programming Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline Printing texts Adding 2 integers Comparing 2 integers C.E.,

### Operators and Control Flow. CS449 Fall 2017

Operators and Control Flow CS449 Fall 2017 Running Example #include /* header file */ int main() { int grade, count, total, average; /* declaramons */ count = 0; /* inimalizamon */ total = 0;

### Solutions to Assessment

Solutions to Assessment 1. In the bad character rule, what are the values of R(P) for the given pattern. CLICKINLINK (Please refer the lecture). Ans: a) C-1,K-10,N-9,I-8,L-2 b) C-1,K-10,N-9,I-8,L-7 c)

### M.CS201 Programming language

Power Engineering School M.CS201 Programming language Lecture 16 Lecturer: Prof. Dr. T.Uranchimeg Agenda Opening a File Errors with open files Writing and Reading File Data Formatted File Input Direct

### Linked-List Basic Examples. A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links

Linked-List Basic Examples A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links Accessed via a pointer to the first node of the list Subsequent

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

7/21/2014 1 FILE INPUT / OUTPUT Dong-Chul Kim BioMeCIS CSE @ UTA What s a file? A named section of storage, usually on a disk In C, a file is a continuous sequence of bytes Examples for the demand of a

### Pointers (part 1) What are pointers? EECS We have seen pointers before. scanf( %f, &inches );! 25 September 2017

Pointers (part 1) EECS 2031 25 September 2017 1 What are pointers? We have seen pointers before. scanf( %f, &inches );! 2 1 Example char c; c = getchar(); printf( %c, c); char c; char *p; c = getchar();

### Introduction to Computing Lecture 03: Basic input / output operations

Introduction to Computing Lecture 03: Basic input / output operations Assist.Prof.Dr. Nükhet ÖZBEK Ege University Department of Electrical & Electronics Engineering nukhet.ozbek@ege.edu.tr Topics Streams

### Homework 4 Answers. Due Date: Monday, May 27, 2002, at 11:59PM Points: 100. /* * macros */ #define SZBUFFER 1024 /* max length of input buffer */

Homework 4 Answers Due Date: Monday, May 27, 2002, at 11:59PM Points: 100 UNIX System 1. (10 points) How do I delete the file i? Answer: Either rm./-i or rm -- -i will work. 2. (15 points) Please list

### NEXT SET OF SLIDES FROM DENNIS FREY S FALL 2011 CMSC313.

NEXT SET OF SLIDES FROM DENNIS FREY S FALL 2011 CMSC313 http://www.csee.umbc.edu/courses/undergraduate/313/fall11/" Programming in C! Advanced Pointers! Reminder! You can t use a pointer until it points

### United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017 1. Do a page check: you should have 8 pages including this cover sheet. 2. You have 50 minutes

### Computer Programming. Pointers. Marius Minea. 20 November 2017

Computer Programming Pointers Marius Minea marius@cs.upt.ro 20 November 2017 Pointers are addresses Any lvalue (variable x, array element, structure field) of type T has an address &x of type T * where

### Binary Search Tree 1.0. Generated by Doxygen Mon Jun :12:39

Binary Search Tree 1.0 Generated by Doxygen 1.7.1 Mon Jun 6 2011 16:12:39 Contents 1 Binary Search Tree Program 1 1.1 Introduction.......................................... 1 2 Data Structure Index 3

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

Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are

### Structured Programming. Functions and Structured Programming. Functions. Variables

Structured Programming Functions and Structured Programming Structured programming is a problem-solving strategy and a programming methodology. The construction of a program should embody topdown design

### CSC 270 Survey of Programming Languages. What is a Pointer?

CSC 270 Survey of Programming Languages C Lecture 6 Pointers and Dynamic Arrays What is a Pointer? A pointer is the address in memory of a variable. We call it a pointer because we envision the address

### COP Programming Concepts Spring 1999 CLOSED BOOK Exam #1 100 Points NAME

CLOSED BOOK Exam #1 100 Points NAME 1. The following program has (at least) 10 syntax errors. Circle each error. Write the corrected program in the blank space below. 2 points for each error you find.

### Fundamentals of Programming Session 8

Fundamentals of Programming Session 8 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2013 These slides have been created using Deitel s slides Sharif University of Technology Outlines

### Topic 6: A Quick Intro To C

Topic 6: A Quick Intro To C Assumption: All of you know Java. Much of C syntax is the same. Also: Many of you have used C or C++. Goal for this topic: you can write & run a simple C program basic functions

### Linked Lists. .. and other linked structures. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

1 Linked Lists.. and other linked structures Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Dynamic memory allocation: review typedef struct { int hitemp;

### CS302 Topic: Fields, Jval, and Dllist. Tuesday, August 30, 2005

CS302 Topic: Fields, Jval, and Dllist Tuesday, August 30, 2005 Announcements Remember: 1 st Labs meet this week Attendance required for 1 st lab!! Class emailing list set up: cs302-students@cs.utk.edu

### Arrays and Strings. Antonio Carzaniga. February 23, Faculty of Informatics Università della Svizzera italiana Antonio Carzaniga

Arrays and Strings Antonio Carzaniga Faculty of Informatics Università della Svizzera italiana February 23, 2015 Outline General memory model Definition and use of pointers Invalid pointers and common

### NAG Library Function Document nag_corr_cov (g02bxc)

1 Purpose NAG Library Function Document nag_corr_cov () nag_corr_cov () calculates the Pearson product-moment correlation coefficients and the variancecovariance matrix for a set of data. Weights may be

### COP 3223 Introduction to Programming with C - Study Union - Fall 2017

COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................

### C: Pointers, Arrays, and strings. Department of Computer Science College of Engineering Boise State University. August 25, /36

Department of Computer Science College of Engineering Boise State University August 25, 2017 1/36 Pointers and Arrays A pointer is a variable that stores the address of another variable. Pointers are similar

### Mid-term Exam. Fall Semester 2017 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:

Fall Semester 2017 KAIST EE209 Programming Structures for Electrical Engineering Mid-term Exam Name: This exam is closed book and notes. Read the questions carefully and focus your answers on what has

### File I/O BJ Furman 23OCT2010

File I/O BJ Furman 23OCT2010 Learning Objectives Explain what is meant by a data stream Explain the concept of a file Open and close files for reading and writing Data Streams Data stream an ordered series

### Why arrays? To group distinct variables of the same type under a single name.

Lesson #7 Arrays Why arrays? To group distinct variables of the same type under a single name. Suppose you need 100 temperatures from 100 different weather stations: A simple (but time consuming) solution

### Pointers and scanf() Steven R. Bagley

Pointers and scanf() Steven R. Bagley Recap Programs are a series of statements Defined in functions Can call functions to alter program flow if statement can determine whether code gets run Loops can

### Arrays. CS10001: Programming & Data Structures. Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur

Arrays CS10001: Programming & Data Structures Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Array Many applications require multiple data items that have common

### Arrays and Pointers in C. Alan L. Cox

Arrays and Pointers in C Alan L. Cox alc@rice.edu Objectives Be able to use arrays, pointers, and strings in C programs Be able to explain the representation of these data types at the machine level, including

### CS 137 Part 2. Loops, Functions, Recursion, Arrays. September 22nd, 2017

CS 137 Part 2 Loops, Functions, Recursion, Arrays September 22nd, 2017 Loops We will finish this week with looping statements We already discussed one such structure, namely while loops. while (expr) statement

### Procedural programming with C

Procedural programming with C Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 77 Functions Similarly to its mathematical

### Work relative to other classes

Work relative to other classes 1 Hours/week on projects 2 C BOOTCAMP DAY 1 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Overview C: A language

### CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0)

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Dynamic Memory Allocation All variables, arrays, structures and unions that we worked with so far are statically allocated, meaning

### Chapter 7 Functions. Now consider a more advanced example:

Chapter 7 Functions 7.1 Chapter Overview Functions are logical groupings of code, a series of steps, that are given a name. Functions are especially useful when these series of steps will need to be done

### Arrays and Pointers. CSE 2031 Fall November 11, 2013

Arrays and Pointers CSE 2031 Fall 2013 November 11, 2013 1 Arrays l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. 2 Arrays: Example

### C library = Header files + Reserved words + main method

DAY 1: What are Libraries and Header files in C. Suppose you need to see an Atlas of a country in your college. What do you need to do? You will first go to the Library of your college and then to the

### 211: Computer Architecture Summer 2016

211: Computer Architecture Summer 2016 Liu Liu Topic: C Programming Structure: - header files - global / local variables - main() - macro Basic Units: - basic data types - arithmetic / logical / bit operators

### Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

1 Functions Functions are everywhere in C Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Introduction Function A self-contained program segment that carries

### NAG Library Function Document nag_all_regsn (g02eac)

g02 Correlation and Regression Analysis g02eac 1 Purpose NAG Library Function Document nag_all_regsn (g02eac) nag_all_regsn (g02eac) calculates the residual sums of squares for all possible linear regressions

### Tutorial 1: Introduction to C Computer Architecture and Systems Programming ( )

Systems Group Department of Computer Science ETH Zürich Tutorial 1: Introduction to C Computer Architecture and Systems Programming (252-0061-00) Herbstsemester 2012 Goal Quick introduction to C Enough

### Arrays in C. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur. Basic Concept

Arrays in C Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur 1 Basic Concept Many applications require multiple data items that have common characteristics.

### C Concepts - I/O. Lecture 19 COP 3014 Fall November 29, 2017

C Concepts - I/O Lecture 19 COP 3014 Fall 2017 November 29, 2017 C vs. C++: Some important differences C has been around since around 1970 (or before) C++ was based on the C language While C is not actually