CMPE13 Cyrus Bazeghi Hands on with Functions and IO.

Slides:



Advertisements
Similar presentations
C: Advanced Topics-II Winter 2013 COMP 2130 Intro Computer Systems Computing Science Thompson Rivers University.
Advertisements

Week 5 Part I Kyle Dewey. Overview Exam will be back Thursday New office hour More on functions File I/O Project #2.
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
1 Lecture13: Other C Topics 12/17/2012. Topics Variable-length argument lists Pointers to functions Command-line arguments Suffixes for integer and floating-point.
A file reminder Files are used to store data and information They are manipulated through a pointer to FILE (FILE *) This pointer is returned when opening.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Introduction Data files –Can be created, updated,
Chapter 11 C File Processing Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Cryptography: Keeping Your Information Safe. Information Assurance/Information Systems –What do we do? Keep information Safe Keep computers Safe –What.
ISP - 2 nd Recitation Functions Pointers Structs Files Code Examples Homework!
Exercise 10 Review: pointers, strings and recursion.
Guide To UNIX Using Linux Third Edition
Computer Science 210 Computer Organization Strings in C.
Command line arguments. – main can take two arguments conventionally called argc and argv. – Information regarding command line arguments are passed to.
Console and File I/O - Basics Rudra Dutta CSC Spring 2007, Section 001.
Review C++ exception handling mechanism Try-throw-catch block How does it work What is exception specification? What if a exception is not caught?
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 15: Linked data structures.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 14 - Advanced C Topics Outline 14.1Introduction 14.2Redirecting Input/Output on UNIX and DOS Systems.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Objectives - 11  We will work with processing Arrays.  Objectives:  Describe the concept of an array and its benefits.  Define the terms index, traverse,
File Handling Spring 2013Programming and Data Structure1.
22. FILE INPUT/OUTPUT. File Pointers and Streams Declarations of functions that perform file I/O appear in. Each function requires a file pointer as a.
CS50 Section 2 21 September 2015 Sam Green ’17 (646)
C++ language first designed or implemented In 1980 by Bjarne Stroustrup, from Bell labs. that would receive formally this name at the end of 1983.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
Characters and Strings File Processing Exercise C Programming:Part 3.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Command Line Arguments.
File IO and command line input CSE 2451 Rong Shi.
EXERCISE Arrays, structs and file processing. Question An online store sells various types of children’s clothing. You are to create a program that stores.
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:
Introduction to Systems Programming (CS 0449) C Preprocessing Makefile File I/O.
Weeks 5-6 Pointers and Arrays Basic pointer type Pointers and Arrays Address arithmetic Pointer Arrays User-defined data types Structures Unions Pointers.
CSE 232: C++ memory management Overview of Arrays Arrays are the simplest kind of data structure –One item right after another in memory (“contiguous range”
EXERCISE Arrays, structs and file processing. Question You own a pet store. You want to keep an inventory of all the pets that you have. Pets available.
Chapter 11 File Processing. Objectives In this chapter, you will learn: –To be able to create, read, write and update files. –To become familiar with.
Validation final steps Stopping gaps being entered in an input.
chap8 Chapter 12 Files (reference: Deitel ’ s chap 11)
Cryptography.
GAME203 – C Files stdio.h C standard Input/Output “getchar()”
Arrays, Strings, and Memory. Command Line Arguments #include int main(int argc, char *argv[]) { int i; printf("Arg# Contents\n"); for (i = 0; i < argc;
 2007 Pearson Education, Inc. All rights reserved. 1 C File Processing.
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.
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
C Tutorial - Pointers CS 537 – Introduction to Operating Systems.
LAB#3 CLASSICAL ENCRYPTION CPIT 425. This diagram is taken from Dr.Omaima slides.
Week 6 - Friday.  What did we talk about last time?  Pointers  Passing values by reference.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
LINKED LISTS.
Lesson #8 Structures Linked Lists Command Line Arguments.
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.
TMF1414 Introduction to Programming
Command Line Arguments
Command line arguments
Command Line Arguments
Prepared by: Sameer Ali Aljaroodi, Tutor: Mr. Ahmad Kananh
CS111 Computer Programming
File I/O We are used to reading from and writing to the terminal:
C Stuff CS 2308.
Exam 4 review Copyright © 2008 W. W. Norton & Company.
Command Line Parameters
File Handling.
Simple Encryption- Lesson 5
EE 312 Exam I Review.
C Preprocessing File I/O
File Handling in C.
Quick Review EECS May 2019.
Double Transpositions
EE 312 Exam I Review.
File I/O We are used to reading from and writing to the terminal:
EE 312 Exam I Review.
Presentation transcript:

CMPE13 Cyrus Bazeghi Hands on with Functions and IO

CMPE13 Program Inputs How do you pass information into your program? Use arguments in main() int main(int argc, char * argv[]) The names argc and argv are usually used for the parameters, but a programmer could use different names. 2

CMPE13 Program Inputs The command words can be accessed as argv[0] through argv[argc - 1]. The program name is the first word on the command line, which is argv[0]. The command-line arguments are argv[1] through argv[argc - 1]. argc holds how many arguments are passed 3

CMPE13 Simple Example #include int main(int argc, char * argv[]) { int i; printf ("You entered %d words\n",argc); for (i = 1; i < argc; i++) printf("%s ", argv[i]); printf("\n"); } 4 Now lets use it

CMPE13 File IO review We have discussed fopen, fclose, fprintf, & fscanf Example: –Look at the file_io.c example 5

CMPE13 More File IO To do more interesting things, need to more fine toothed control… fgetc() – Reads one character from a file fputc() – Writes one character from a file Example: my_cat.c 6

CMPE13 Basic Database Get the file “database.txt” from the class website in the Handouts and Links section Write a simple function that will read the elements out of the database and add them to a linked list that you dynamically create –You will need to make a structure to hold them –You will need a function to add a node to the linked list Now write 2 functions, one to add a node, one to delete, the add should prompt the user for the fields, the delete should ask for the ID or name Write a final function that will save the database back to the file

CMPE13 Caesar Cipher Algorithm 8 Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet.encryptionsubstitution cipherplaintextalphabet

CMPE13 Activity Write two functions, one called Caesar_Encrypt() the other called Caesar_Decrypt(). The Caesar_Encrypt should take 2 inputs, a string of characters and a key. The function should shift the characters by the key and account for “roll-around” at the end of the alphabet. The Caesar_Decrypt() should take the same types of input as the Caesar_Encrypt() function but reverse the process. Test the above with some character arrays. Put the functions in a file called crypto.c and make a header called crypto.h Now uses these to read in a file of text and produce a new file with the extension “.enc” 9 Part 1: Part 2: