ECE 103 Engineering Programming Chapter 51 Random Numbers

Slides:



Advertisements
Similar presentations
Lecture 3 Some commonly used C programming tricks. The system command Project No. 1: A warm-up project.
Advertisements

Starting Out with C++, 3 rd Edition 1 Chapter 10 – Characters, Strings, and the string Class.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 16P. 1Winter Quarter Strings Lecture 16.
ECE 103 Engineering Programming Chapter 54 Recursion Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material developed.
Strings Input/Output scanf and printf sscanf and sprintf gets and puts.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Characters and Strings.
Dale Roberts Basic I/O – scanf() CSCI 230 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Department of.
CS1061: C Programming Lecture 19: Random Access Files A. O’Riordan, 2004, 2007 updated.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
Console and File I/O - Basics Rudra Dutta CSC Spring 2007, Section 001.
C - Input & Output When we are saying Input that means to feed some data into program. This can be given in the form of file or from command line. C programming.
CS 161 Introduction to Programming and Problem Solving Chapter 13 Console IO Herbert G. Mayer, PSU Status 9/8/2014 Initial content copied verbatim from.
Strings in C. Strings are Character Arrays Strings in C are simply arrays of characters. – Example:char s [10]; This is a ten (10) element array that.
Chapter 5: Data Input and Output Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
Chapter 9 Character Strings 9.1 Character String Constants A character string constant is a sequence of characters enclosed in double quotation mark. Examples.
ECE 103 Engineering Programming Chapter 57 Terminal Control Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material.
CS 162 Introduction to Computer Science Chapter 17 C++ String Objects Herbert G. Mayer, PSU (Copied from Prof. Phillip Wong at PSU) Status 11/30/2014.
ECE 103 Engineering Programming Chapter 48 Typedef and Enum Type Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103.
File IO and command line input CSE 2451 Rong Shi.
ECE 103 Engineering Programming Chapter 44 File I/O Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material developed.
ECE 103 Engineering Programming Chapter 53 Generic Algorithms Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material.
ECE 103 Engineering Programming Chapter 31 C Scopes Herbert G. Mayer, PSU CS Status 8/1/2015 Initial content copied verbatim from ECE 103 material developed.
ECE 103 Engineering Programming Chapter 15 C Standard Library Herbert G. Mayer, PSU CS Status 7/19/2015 Initial content copied verbatim from ECE 103 material.
ECE 103 Engineering Programming Chapter 41 C Pointers, Part 3 Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic properties and characteristics of external files ❏ To.
IO revisited CSE 2451 Rong Shi. stdio.h Functions – printf – scanf(normally stops at whitespace) – fgets – sscanf Standard streams – stdin(defaults to.
CSE 251 Dr. Charles B. Owen Programming in C1 Strings and File I/O.
ECE 103 Engineering Programming Chapter 29 C Strings, Part 2 Herbert G. Mayer, PSU CS Status 7/30/2014 Initial content copied verbatim from ECE 103 material.
Strings C supports strings using one-dimensional character arrays. A string is defined as a null-terminated character array. In C, a null is 0. You must.
Chapter 9 - Formatted Input/Output
‘C’ Programming Structures and Commands
INC 161 , CPE 100 Computer Programming
Chapter 7 Text Input/Output Objectives
Chapter 7 Text Input/Output Objectives
Lecture 8 String 1. Concept of strings String and pointers
Chapter 7 Text Input/Output Objectives
Functions, Part 2 of 2 Topics Functions That Return a Value
C Programming Tutorial – Part I
Number guessing game Pick a random number between 1 and 10
Plan for the Day: I/O (beyond scanf and printf)
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
CS 106 Computing Fundamentals II Chapter 71 “Indexing”
CS 161 Introduction to Programming
Chapter 9 - Formatted Input/Output
Systems Programming Concepts
ECE 103 Engineering Programming Chapter 32 Array Parameters
ECE 103 Engineering Programming Chapter 56 Runtime Errors
ECE 103 Engineering Programming Chapter 19 Nested Loops
ECE 103 Engineering Programming Chapter 12 More C Statements
ECE 103 Engineering Programming Chapter 25 C Strings, Part 1
ECE 103 Engineering Programming Chapter 46 argc, argv, envp
ECE 103 Engineering Programming Chapter 37 C Macro Parameters
ECE 103 Engineering Programming Chapter 8 Data Types and Constants
ECE 103 Engineering Programming Chapter 62 Stack Implementation
ECE 103 Engineering Programming Chapter 64 Tree Implementation
ECE 103 Engineering Programming Chapter 20 Change in Flow of Control
ECE 103 Engineering Programming Chapter 35 C Pointers, Part 1
EECE.2160 ECE Application Programming
ECE 103 Engineering Programming Chapter 38 C Pointers, Part 2
ECE 103 Engineering Programming Chapter 18 Iteration
Character Arrays char string1[] = “first”;
Strings #include <stdio.h>
ETE 132 Lecture 8 By Munirul Haque.
EECE.2160 ECE Application Programming
Professor Jodi Neely-Ritz University of Florida
Systems Programming Concepts
Files Chapter 8.
Presentation transcript:

ECE 103 Engineering Programming Chapter 51 Random Numbers Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material developed by Professor Phillip Wong @ PSU ECE

Syllabus srand() sand()

Random Number Generator C has library functions to input and output strings. Use #include <stdio.h> In the following table, char * is a pointer to a character array that contains a string. RNG Functions void srand (unsigned int seed) Initializes the RNG with a seed value int rand (void) Returns a pseudo-random integral number 2

String I/O Functions C has library functions to input and output strings. Use #include <stdio.h> In the following table, char * is a pointer to a character array that contains a string. int printf (const char * fmt, …) Prints formatted output to console int sprintf (char * s, const char * fmt, …) Prints formatted output to string int puts (const char * s) Prints string to console int scanf (const char * fmt, …) Reads formatted input from console int fgets (const char * s, FILE * stream) Reads string from input stream 3

srand int printf (const char * format, …) Writes formatted output to the console. Use the %s format specifier for strings. %s expects the address of a char array which contains a string. Example: char name[] = "Jane Doe"; printf("[%s]\n", name); → [Jane Doe] printf("[%s]\n", &name[0]); → [Jane Doe] printf("[%s]\n", &name[5]); → [Doe] 4

rand int sprintf (char * s, const char * format, …) Performs a formatted print and saves it to a string. Works like printf except the output is stored in string s. Nothing is printed to the console. Example: char str[50]; int x = 4; sprintf(str,"x=%d y=%f", x, 1.5f); printf("title = %s\n", str); 5