CSC UNIX System, Spring 2015
|
|
- Christal Lang
- 5 years ago
- Views:
Transcription
1 ` CSC UNIX System, Spring 2015 Assignment 2, due by 11:59 on Friday March 6 via gmake turnitin. Dr. Dale E. Parson, The directory, source-file and makefile contents of this project are isomorphic with the runcat2 handout at that we are going over in class. Isomorphic means that they have identical overall form or structure. The individual C source files and makefiles in each project differ with respect to what they accomplish, but the number, location and overall interaction of the makefile-driven buildand-test machinery with the source code is essentially identical in runcat2 and this assignment project. Below is the runcat2 diagram from the above-linked page. test1.ref test2.ref diff test1.out test1.ref > test1.dif test1.dif test2.dif diff test2.out test2.ref > test2.dif test1.out test2.out runcat2 gcc -c -g -I./include runcat2.c -o runcat2.o gcc runcat2.o -L./lib -l runcat2 -o runcat2 runcat2.c runcat2.o include/runcatlib.h lib/libruncat2.a runcatlib/run1cmd.c runcatlib/run1cmd.o /usr/ccs/bin/ar -rv../lib/libruncat2.a run1cmd.o gcc -c -g -I../include run1cmd.c -o run1cmd.o CSC 352, Assignment 2, due March 6, page 1 of 12, Spring 2015
2 I recommend downloading your project ZIP file, unzipping it in your unix directory, looking through it, and then replacing directory and file names in the above diagram with the directory and file names for your project. Make a map of your project. You might also download and unzip the project runcat2.zip to serve as a template. You can find runcat2 in ~parson/unix/runcat2.zip. This project has all of the C source code but is missing the makefiles and reference files for building and testing: cd ~/unix cp ~parson/unix/factor2.problem.zip factor2.problem.zip unzip factor2.problem.zip cd factor2 find. -type f -print./makelib./factorlib/factor.c./include/factorlib.h./testfactor.c Files include/factorlib.h, factorlib/factor.c and testfactor.c define a function for factoring int values into primes and reporting results or error message. Your job is to write two makefiles, one in directory factor2 and the other in subdirectory factor2/factorlib. You can pattern them after the two makefiles in runcat2. Here is what GNU make shows when I run it in my solution to this problem. [:-) ~/.../solution/factor2] gmake clean /bin/rm -f *.o *.class core *.exe *.obj *.pyc /bin/rm -f *.o factor2 *.dif *.out cd./factorlib && make clean /bin/rm -f *.o *.class core *.exe *.obj *.pyc /bin/rm -f *.o../lib/libfactor2.a *.dif *.out [:-) ~/.../solution/factor2] gmake cd./factorlib && make build gcc -c -g -I../include factor.c -o factor.o ar -rv../lib/libfactor2.a factor.o ar: creating../lib/libfactor2.a a - factor.o make factor2 make[1]: Entering directory `/home/kutztown/parson/private/csc352/solution/factor2' gcc -c -g -I./include testfactor.c -o testfactor.o gcc testfactor.o -L./lib -l factor2 -o factor2 make[1]: Leaving directory `/home/kutztown/parson/private/csc352/solution/factor2' [:-) ~/.../solution/factor2] gmake test cd./factorlib && make build make[1]: Nothing to be done for `build'. make factor2 make[1]: Entering directory `/home/kutztown/parson/private/csc352/solution/factor2' make[1]: `factor2' is up to date. make[1]: Leaving directory `/home/kutztown/parson/private/csc352/solution/factor2' /bin/rm -f *.dif CSC 352, Assignment 2, due March 6, page 2 of 12, Spring 2015
3 cd./factorlib && make test make[1]: Nothing to be done for `test'../factor > test1.out 2>&1./factor > test2.out 2>&1./factor > test3.out 2>test3.err.out make: [test] Error 1 (ignored)./factor2 2 oops > test4.out 2> test4.err.out make: [test] Error 1 (ignored) diff test1.out test1.ref > test1.dif diff test2.out test2.ref > test2.dif diff test3.out test3.ref > test3.dif diff test3.err.out test3.err.ref > test3.err.dif diff test4.out test4.ref > test4.dif diff test4.err.out test4.err.ref > test4.err.dif Notice that my makefiles have four test cases. The first two have no data errors, while the last two do. Factoring the values -31, 0, and 1 for primes is undefined, as is the string oops in the last test run. In those cases my C code exits with an exit status of 1, indicating an error. Normally, when a program exits with a non-0 exit code (indicating an error), you want the makefile to stop and report the error. That is what happens by default. However, sometimes you want to run a program with data errors to ensure that the program handles the errors correctly and terminates with a non-0 exit status. That is the case in the last two lines above. In those cases, the line in the makefile that runs the test that you expect to fail must start with a - character. The - tells GNU make to ignore any non-0 exit status because it is expected. Notice in the above test run that some tests redirect standard error output like this 2>&1, thereby sending it to the same output file as standard output. However, test3 and test4 use output redirection > test3.out 2>test3.err.out and > test4.out 2> test4.err.out respectively, creating different output files for standard output and standard error output. Your makefiles should do similar output redirection to two files for test runs that you expect to exit with errors. The C files send normal output to stdout and error messages to stderr. This means that, once you have written the two makefiles, you must use gmake test to run tests and to create.out files for which you have no.ref files to compare using diff. Just look at the.out files to see if they contain correct CSC 352, Assignment 2, due March 6, page 3 of 12, Spring 2015
4 output. If they do, cp them to their corresponding.ref files and run gmake test again. Eventually your test results should look similar to mine above. Make sure to use diff to compare C program.out files to the expected.ref files. I recommend starting by copying the makefile for runcat2 and editing that, likewise the makefile for the subdirectory with the library.c file. You can do this assignment mostly by changing makefile variables names, directory names, and rewriting the test lines. You can find runcat2 in ~parson/unix/runcat2.zip. Students can compile and run the program by hand to play with it, but ultimately all compilation, archiving (with ar), linking and testing must be driven by the makefile in a manner that uses ar to build a code archive of the compiled library function, and uses gcc to link a final executable as shown by my makefile trace above (gcc testfactor.o -L./lib -l factor -o testfactor). Here is how you can try it by hand in the meantime. -bash-3.00$ gcc -I `pwd`/include testfactor.c factorlib/factor.c -o testfactor -bash-3.00$./testfactor 10 The 2 factors for integer 10 are: 2 5 -bash-3.00$ echo $? # shows exit status 0 PROJECT FILES: factor2/include/factorlib.h 1 #ifndef FACTORLIB_H 2 #define FACTORLIB_H 3 /** 4 factorlib.h 5 Declarations of C functions used in C source code by the IT 6 assignment #3 for CSC 352. Students will write makefiles and tests. 7 Spring 2015 Dr. Dale Parson, CSC 352, UNIX 8 **/ 9 10 /** 11 * Function isdecimalstring returns true if str consists of an optional 12 * "-" character, followed by 1 or more decimal digits, else returing false. 13 * Return value true is actually non-0, false is 0 (this is C, not C++). 14 **/ 15 int isdecimalstring(const char *str); /** 18 * factorstring converts its str parameter into an integer, then 19 * factors that integer into its prime factors. Three conditions are possible: 20 * 1. If the null-character-terminated character sequence to which str 21 * points is not a valid signed decimal string, factorstring sets 22 * *status to FACTOR_ERR_NOT_A_DECIMAL_STRING (a negative constant) 23 * and returns a NULL pointer. factorstring uses isdecimalstring 24 * for this test. 25 * 2. Else if the translated int is <= 1, factorstring returns a 26 * a pointer to a single int (equivalent to a 1-element int array) 27 * with the int value of the string, and sets *status to 28 * FACTOR_ERR_CANNOT_FACTOR (a negative constant) and returns 29 * a pointer to a one-element in [] allocated using malloc(). 30 * The caller must eventually free the return array using free(). CSC 352, Assignment 2, due March 6, page 4 of 12, Spring 2015
5 31 * 3. Otherwise that decimal value is > 1, in which case factorstring 32 * returns an array with the original integer at [0], followed by 33 * all the factors in the remaining array elements [1].. [(*status)-1], 34 * and sets *status to the number of ints in the returned array, >= * The caller must eventually free the return array using free(). 36 **/ 37 int * factorstring(const char *str, int *status); /** See above for the use of these #defined constants. **/ 40 #define FACTOR_ERR_NOT_A_DECIMAL_STRING (-1) 41 #define FACTOR_ERR_CANNOT_FACTOR (-2) #endif factor2/testfactor.c 1 /** 2 testfactor.c is a test driver to test the functions declared 3 in factorlib.h. This example C program is for the makefile/regression 4 testing option of assignment 3 for CSC Spring 2015, Dr. Dale Parson, CSC 352, UNIX 6 **/ 7 8 #include <stdlib.h> /* library with free */ 9 #include <stdio.h> /* library with printf */ 10 #include "factorlib.h" /* declaration for functions being tested */ int main(int argc, char* argv[]) { 13 const int SUCCESS = 0 ; /* Exit status meaning no errors. */ 14 const int BADPARAM = 1 ; /* Exit status for bad int value string */ 15 int exitstatus = SUCCESS ; 16 int i, j ; 17 for (i = 1 ; i < argc ; i++) { /* Loop over command line arguments. */ 18 int status ; 19 int * factor = factorstring(argv[i], &status); 20 if (status == FACTOR_ERR_NOT_A_DECIMAL_STRING) { 21 fprintf(stderr,"error, %s is not a decimal integer, argument %d.\n", 22 argv[i], i); 23 exitstatus = BADPARAM ; 24 } else if (status == FACTOR_ERR_CANNOT_FACTOR) { 25 fprintf(stderr,"error, %d cannot be factored, argument %d.\n", 26 factor[0], i); 27 free(factor); /* Free storage per declaration of factorstring. */ 28 exitstatus = BADPARAM ; 29 } else { 30 printf("the %d factors for integer %d are:\n\t", 31 status-1, factor[0]); 32 for (j = 1 ; j < status ; j++) { 33 printf("%d ", factor[j]); 34 } 35 printf("\n"); 36 free(factor); /* Free storage per declaration of factorstring. */ 37 } 38 } 39 exit(exitstatus); 40 } factor2/ factorlib/factor.c 1 /** CSC 352, Assignment 2, due March 6, page 5 of 12, Spring 2015
6 2 factor.c 3 Functions declared in factorlib.h. See factorlib.h. 4 Spring 2015 Dr. Dale Parson, CSC 352, UNIX 5 **/ 6 7 #include <ctype.h> /* library with isdigit */ 8 #include <string.h> /* library with strlen */ 9 #include <stdlib.h> /* library with atoi, malloc etc. */ 10 #include "factorlib.h" /* declaration for run1cmd */ int 13 isdecimalstring(const char *str) { 14 int allok ; 15 if (*str == '-') { /* skip over optional minus sign for now */ 16 str++ ; 17 } 18 allok = (strlen(str) > 0); /* There must be at least 1 char. */ 19 while (allok && (*str!= '\0')) { 20 /* While no problem found and not at terminating null. */ 21 allok = isdigit(*str); /* This is a digit. */ 22 str++ ; /* Next character. */ 23 } 24 return allok ; 25 } int * factorstring(const char *str, int *status) { 28 int * result ; 29 if (! isdecimalstring(str)) { 30 *status = FACTOR_ERR_NOT_A_DECIMAL_STRING ; 31 result = NULL ; 32 } else { 33 int arraycount = 1 ; 34 result = malloc(sizeof(int)); 35 result[0] = atoi(str); 36 if (result[0] <= 1) { 37 *status = FACTOR_ERR_CANNOT_FACTOR ; 38 } else { 39 int todo = result[0] ; 40 while (todo > 1) { 41 int rem = todo % 2 ; /* Remainder of division by 2. */ 42 if (rem == 0) { 43 arraycount++ ; 44 result = realloc(result, arraycount * sizeof(int)); 45 result[arraycount-1] = 2 ; 46 todo = todo / 2 ; 47 } else { 48 int f ; 49 for (f = 3 ; f <= todo ; f += 2) { 50 rem = todo % f ; 51 if (rem == 0) { 52 arraycount++ ; 53 result = realloc(result, arraycount * sizeof(int)); 54 result[arraycount-1] = f ; 55 todo = todo / f ; 56 if (todo == 1) { 57 break ; 58 } 59 f = 1 ; /* Restart the loop at f = 3. */ CSC 352, Assignment 2, due March 6, page 6 of 12, Spring 2015
7 60 } 61 } 62 } 63 } 64 *status = arraycount ; 65 } 66 } 67 return result ; 68 } factor2/makelib 1 # makelib for package factor2 in CSC 352 UNIX 2 # The common make declarations for all makefiles in this 3 # two-directory project go into this makelib. 4 # Spring, 2015, Dr. Dale Parson 5 6 # := assignment is expanded immediately 7 # = assignment is expanded recursively when actually needed, 8 # meaning that = expansion can use make variables before they are defined CFILES := $(wildcard *.c) 11 OBJFILES := $(subst.c,.o,$(cfiles)) 12 CFLAGS := -c ifeq ($(DEBUG),1) 15 CFLAGS += -g 16 endif 17 AR = ar %.o : %.c 20 gcc $(CFLAGS) $< -o $@ subclean: FORCE 23 /bin/rm -f *.o *.class $(JARFILE) core *.exe *.obj *.pyc clean: FORCE FORCE: # Following are need for "gmake turnitin" to work STUDENT := $(shell /bin/basename $$HOME) 32 WORKDIR := $(shell /bin/basename `pwd`) turnitin: clean Do you really want to send $(TARGET) to Professor Parson? Hit Enter to continue, control-c to abort. keyboard 40 /bin/bash -c "cd.. ; /bin/chmod 700. ; \ 41 /bin/tar cvf./$(target)_$(student).tar $(WORKDIR) ; \ 42 /bin/gzip./$(target)_$(student).tar ; \ 43 /bin/chmod 666./$(TARGET)_$(STUDENT).tar.gz ; \ 44 /bin/mv./$(target)_$(student).tar.gz ~parson/incoming" CSC 352, Assignment 2, due March 6, page 7 of 12, Spring 2015
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
More informationPRINCIPLES OF OPERATING SYSTEMS
PRINCIPLES OF OPERATING SYSTEMS Tutorial-1&2: C Review CPSC 457, Spring 2015 May 20-21, 2015 Department of Computer Science, University of Calgary Connecting to your VM Open a terminal (in your linux machine)
More informationExercise 1: Basic Tools
Exercise 1: Basic Tools This exercise is created so everybody can learn the basic tools we will use during this course. It is really more like a tutorial than an exercise and, you are not required to submit
More informationch = argv[i][++j]; /* why does ++j but j++ does not? */
CMPS 12M Introduction to Data Structures Lab Lab Assignment 4 The purpose of this lab assignment is to get more practice programming in C, including the character functions in the library ctype.h, and
More informationFriday, February 10, Lab Notes
Friday, February 10, 2017 Lab Notes Topics for today Structures in C Redirection of input and output in a Unix-like environment Command line arguments More pre-processor options Programs: Finish Program
More informationCSC UNIX System, Spring 2015
CSC 352 - UNIX System, Spring 2015 Study guide for the CSC352 midterm exam (20% of grade). Dr. Dale E. Parson, http://faculty.kutztown.edu/parson We will have a midterm on March 19 on material we have
More informationTHE C STANDARD LIBRARY & MAKING YOUR OWN LIBRARY. ISA 563: Fundamentals of Systems Programming
THE C STANDARD LIBRARY & MAKING YOUR OWN LIBRARY ISA 563: Fundamentals of Systems Programming Announcements Homework 2 posted Homework 1 due in two weeks Typo on HW1 (definition of Fib. Sequence incorrect)
More informationCS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco
CS 326 Operating Systems C Programming Greg Benson Department of Computer Science University of San Francisco Why C? Fast (good optimizing compilers) Not too high-level (Java, Python, Lisp) Not too low-level
More informationCAAM 420 Daily Note. Scriber: Qijia Jiang. Date: Oct.16. Project 3 Due Wed 23.Oct. Two parts: debug code and library exercise.
CAAM 420 Daily Note Scriber: Qijia Jiang Date: Oct.16 1 Announcement Project 3 Due Wed 23.Oct. Two parts: debug code and library exercise. 2 Make Convention Make syntax for library directories and library
More informationUnderstanding 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
More informationCSci 4061 Introduction to Operating Systems. Programs in C/Unix
CSci 4061 Introduction to Operating Systems Programs in C/Unix Today Basic C programming Follow on to recitation Structure of a C program A C program consists of a collection of C functions, structs, arrays,
More informationare all acceptable. With the right compiler flags, Java/C++ style comments are also acceptable.
CMPS 12M Introduction to Data Structures Lab Lab Assignment 3 The purpose of this lab assignment is to introduce the C programming language, including standard input-output functions, command line arguments,
More information15213 Recitation Section C
15213 Recitation Section C Outline Sept. 9, 2002 Introduction Unix and C Playing with Bits Practice Problems Introducing Myself Try to pronounce my name: My office hour: Wed 2-3pm, WeH 8019 Contact: Email:
More informationCSC209H 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
More informationDeep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems
Deep C Multifile projects Getting it running Data types Typecasting Memory management Pointers Fabián E. Bustamante, Fall 2004 Multifile Projects Give your project a structure Modularized design Reuse
More informationSoftware Development With Emacs: The Edit-Compile-Debug Cycle
Software Development With Emacs: The Edit-Compile-Debug Cycle Luis Fernandes Department of Electrical and Computer Engineering Ryerson Polytechnic University August 8, 2017 The Emacs editor permits the
More informationCMPT 300. Operating Systems. Brief Intro to UNIX and C
CMPT 300 Operating Systems Brief Intro to UNIX and C Outline Welcome Review Questions UNIX basics and Vi editor Using SSH to remote access Lab2(4214) Compiling a C Program Makefile Basic C/C++ programming
More informationRicardo Rocha. Department of Computer Science Faculty of Sciences University of Porto
Ricardo Rocha Department of Computer Science Faculty of Sciences University of Porto Adapted from the slides Revisões sobre Programação em C, Sérgio Crisóstomo Compilation #include int main()
More informationLab Exam 1 D [1 mark] Give an example of a sample input which would make the function
CMPT 127 Spring 2019 Grade: / 20 First name: Last name: Student Number: Lab Exam 1 D400 1. [1 mark] Give an example of a sample input which would make the function scanf( "%f", &f ) return -1? Answer:
More informationLecture 03 Bits, Bytes and Data Types
Lecture 03 Bits, Bytes and Data Types Computer Languages A computer language is a language that is used to communicate with a machine. Like all languages, computer languages have syntax (form) and semantics
More informationKurt Schmidt. October 30, 2018
to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed
More informationIntroduction to Supercomputing
Introduction to Supercomputing TMA4280 Introduction to UNIX environment and tools 0.1 Getting started with the environment and the bash shell interpreter Desktop computers are usually operated from a graphical
More informationRecitation 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
More informationDynamic Memory Allocation and Command-line Arguments
Dynamic Memory Allocation and Command-line Arguments CSC209: Software Tools and Systems Programming Furkan Alaca & Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Week 3
More informationProject 2: Shell with History1
Project 2: Shell with History1 See course webpage for due date. Submit deliverables to CourSys: https://courses.cs.sfu.ca/ Late penalty is 10% per calendar day (each 0 to 24 hour period past due). Maximum
More informationBasic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island
Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Data Types Basic Types Enumerated types The type void Derived types
More informationCSC 310 Programming Languages, Spring 2014, Dr. Dale E. Parson
CSC 310 Programming Languages, Spring 2014, Dr. Dale E. Parson Assignment 3, Perquacky in Python, due 11:59 PM, Saturday April 12, 2014 I will turn the solution back on Monday April 14, after which I will
More informationDynamic memory allocation
Dynamic memory allocation outline Memory allocation functions Array allocation Matrix allocation Examples Memory allocation functions (#include ) malloc() Allocates a specified number of bytes
More informationIntermediate Programming, Spring 2017*
600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general
More informationLecture 12 CSE July Today we ll cover the things that you still don t know that you need to know in order to do the assignment.
Lecture 12 CSE 110 20 July 1992 Today we ll cover the things that you still don t know that you need to know in order to do the assignment. 1 The NULL Pointer For each pointer type, there is one special
More informationCSE 333 Autumn 2013 Midterm
CSE 333 Autumn 2013 Midterm Please do not read beyond this cover page until told to start. A question involving what could be either C or C++ is about C, unless it explicitly states that it is about C++.
More informationcs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).
cs3157: another C lecture (mon-21-feb-2005) C pre-processor (1). today: C pre-processor command-line arguments more on data types and operators: booleans in C logical and bitwise operators type conversion
More informationWorkshop Agenda Feb 25 th 2015
Workshop Agenda Feb 25 th 2015 Time Presenter Title 09:30 T. König Talk bwhpc Concept & bwhpc-c5 - Federated User Support Activities 09:45 R. Walter Talk bwhpc architecture (bwunicluster, bwforcluster
More informationC for C++ Programmers
C for C++ Programmers CS230/330 - Operating Systems (Winter 2001). The good news is that C syntax is almost identical to that of C++. However, there are many things you're used to that aren't available
More informationmith College Computer Science CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut
mith College CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut dthiebaut@smith.edu Learning C in 2 Hours D. Thiebaut Dennis Ritchie 1969 to 1973 AT&T Bell Labs Close to Assembly Unix Standard
More informationTutorial 1 C Tutorial: Pointers, Strings, Exec
TCSS 422: Operating Systems Institute of Technology Spring 2017 University of Washington Tacoma http://faculty.washington.edu/wlloyd/courses/tcss422 Tutorial 1 C Tutorial: Pointers, Strings, Exec The purpose
More informationCSE 303 Midterm Exam
CSE 303 Midterm Exam October 29, 2008 Name Sample Solution The exam is closed book, except that you may have a single page of hand written notes for reference. If you don t remember the details of how
More information8. Characters, Strings and Files
REGZ9280: Global Education Short Course - Engineering 8. Characters, Strings and Files Reading: Moffat, Chapter 7, 11 REGZ9280 14s2 8. Characters and Arrays 1 ASCII The ASCII table gives a correspondence
More informationBIL 104E Introduction to Scientific and Engineering Computing. Lecture 14
BIL 104E Introduction to Scientific and Engineering Computing Lecture 14 Because each C program starts at its main() function, information is usually passed to the main() function via command-line arguments.
More informationTHE UNIVERSITY OF WESTERN ONTARIO. COMPUTER SCIENCE 211a FINAL EXAMINATION 17 DECEMBER HOURS
Computer Science 211a Final Examination 17 December 2002 Page 1 of 17 THE UNIVERSITY OF WESTERN ONTARIO LONDON CANADA COMPUTER SCIENCE 211a FINAL EXAMINATION 17 DECEMBER 2002 3 HOURS NAME: STUDENT NUMBER:
More informationArray Initialization
Array Initialization Array declarations can specify initializations for the elements of the array: int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 ; initializes primes[0] to 2, primes[1] to 3, primes[2]
More informationIntermediate Programming, Spring 2017*
600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general
More informationComputer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview
Computer Science 322 Operating Systems Mount Holyoke College Spring 2010 Topic Notes: C and Unix Overview This course is about operating systems, but since most of our upcoming programming is in C on a
More informationCSCI-243 Exam 2 Review February 22, 2015 Presented by the RIT Computer Science Community
CSCI-43 Exam Review February, 01 Presented by the RIT Computer Science Community http://csc.cs.rit.edu C Preprocessor 1. Consider the following program: 1 # include 3 # ifdef WINDOWS 4 # include
More informationYork University Faculty Science and Engineering Fall 2008
York University Faculty Science and Engineering Fall 2008 CSE2031 Final Software Tools Friday, Feb..26 th, 2008 Last Name 08:30 10:30am First name ID Instructions to students: Answer all questions. Marks
More informationThe output: The address of i is 0xbf85416c. The address of main is 0x80483e4. arrays.c. 1 #include <stdio.h> 3 int main(int argc, char **argv) 4 {
Memory A bit is a binary digit, either 0 or 1. A byte is eight bits, and can thus represent 256 unique values, such as 00000000 and 10010110. Computer scientists often think in terms of hexadecimal, rather
More informationBasic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island
Basic C Programming Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Announcements Exam 1 (20%): Feb. 27 (Tuesday) Tentative Proposal Deadline:
More informationFinal CSE 131B Spring 2004
Login name Signature Name Student ID Final CSE 131B Spring 2004 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 (25 points) (24 points) (32 points) (24 points) (28 points) (26 points) (22 points)
More informationOutline. Lecture 1 C primer What we will cover. If-statements and blocks in Python and C. Operators in Python and C
Lecture 1 C primer What we will cover A crash course in the basics of C You should read the K&R C book for lots more details Various details will be exemplified later in the course Outline Overview comparison
More informationCSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community
CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine
More informationContents. A Review of C language. Visual C Visual C++ 6.0
A Review of C language C++ Object Oriented Programming Pei-yih Ting NTOU CS Modified from www.cse.cuhk.edu.hk/~csc2520/tuto/csc2520_tuto01.ppt 1 2 3 4 5 6 7 8 9 10 Double click 11 12 Compile a single source
More informationFundamentals of Programming
Fundamentals of Programming Introduction to the C language Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) The C language
More informationAgenda. Components of a Computer. Computer Memory Type Name Addr Value. Pointer Type. Pointers. CS 61C: Great Ideas in Computer Architecture
CS 61C: Great Ideas in Computer Architecture Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c And in Conclusion, 2 Processor Control Datapath Components of a Computer PC Registers Arithmetic
More informationCSC209H1S Day Midterm Solutions Winter 2010
Duration: Aids Allowed: 50 minutes 1-8.5x11 sheet Student Number: Last Name: SOLUTION First Name: Instructor: Karen Reid Do not turn this page until you have received the signal to start. (In the meantime,
More informationCS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Krste Asanović & Randy Katz
CS 61C: Great Ideas in Computer Architecture Lecture 3: Pointers Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c Agenda Pointers in C Arrays in C This is not on the test Pointer arithmetic
More informationStrings and Stream I/O
Strings and Stream I/O C Strings In addition to the string class, C++ also supports old-style C strings In C, strings are stored as null-terminated character arrays str1 char * str1 = "What is your name?
More informationMain Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University
C Programming Notes Dr. Karne Towson University Reference for C http://www.cplusplus.com/reference/ Main Program #include main() printf( Hello ); Comments: /* comment */ //comment 1 Data Types
More informationSaint Louis University. Intro to Linux and C. CSCI 2400/ ECE 3217: Computer Architecture. Instructors: David Ferry
Intro to Linux and C CSCI 2400/ ECE 3217: Computer Architecture Instructors: David Ferry 1 Overview Linux C Hello program in C Compiling 2 History of Linux Way back in the day: Bell Labs Unix Widely available
More information23. Check that hello.txt now contains (substitute your info for mine): hello rcwhaley: Dr. Whaley
Assignment 0: Basic Unix Exploration Due: Wednesday 01/15/2018 (before class) In this assignment, you will become familiar with a few tools required to work in the Unix environment. Take your time, and
More informationEL2310 Scientific Programming
Lecture 11: Memory, Files and Bitoperations (yaseminb@kth.se) Overview Overview Lecture 11: Memory, Files and Bit operations Main function; reading and writing Bitwise Operations Lecture 11: Memory, Files
More informationCSCI 2132 Final Exam Solutions
Faculty of Computer Science 1 CSCI 2132 Final Exam Solutions Term: Fall 2018 (Sep4-Dec4) 1. (12 points) True-false questions. 2 points each. No justification necessary, but it may be helpful if the question
More informationProgramming Language B
Programming Language B Takako Nemoto (JAIST) 7 January Takako Nemoto (JAIST) 7 January 1 / 13 Usage of pointers #include int sato = 178; int sanaka = 175; int masaki = 179; int *isako, *hiroko;
More informationChapter 11 Introduction to Programming in C
Chapter 11 Introduction to Programming in C C: A High-Level Language Gives symbolic names to values don t need to know which register or memory location Provides abstraction of underlying hardware operations
More informationCSC111 Computer Science II
CSC111 Computer Science II Lab 1 Getting to know Linux Introduction The purpose of this lab is to introduce you to the command line interface in Linux. Getting started In our labs If you are in one of
More informationCS 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
More informationCSE 333 Lecture 7 - final C details
CSE 333 Lecture 7 - final C details Steve Gribble Department of Computer Science & Engineering University of Washington Today s topics: - a few final C details header guards and other preprocessor tricks
More informationCS 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)
More informationFrom Java to C. Thanks to Randal E. Bryant and David R. O'Hallaron (Carnegie-Mellon University) for providing the basis for these slides
From Java to C Thanks to Randal E. Bryant and David R. O'Hallaron (Carnegie-Mellon University) for providing the basis for these slides 1 Outline Overview comparison of C and Java Good evening Preprocessor
More informationInformatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 5, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction
More informationCS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Bernhard Boser & Randy Katz
CS 61C: Great Ideas in Computer Architecture Lecture 3: Pointers Bernhard Boser & Randy Katz http://inst.eecs.berkeley.edu/~cs61c Agenda Pointers in C Arrays in C This is not on the test Pointer arithmetic
More informationmith College Computer Science CSC231 Bash Labs Week #10, 11, 12 Spring 2017 Introduction to C Dominique Thiébaut
mith College CSC231 Bash Labs Week #10, 11, 12 Spring 2017 Introduction to C Dominique Thiébaut dthiebaut@smith.edu Learning C in 4 Hours! D. Thiebaut Dennis Ritchie 1969 to 1973 AT&T Bell Labs Close to
More informationOregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 2. Spring 2016
Oregon State University School of Electrical Engineering and Computer Science CS 261 Recitation 2 Spring 2016 Outline Programming in C o Headers o Structures o Preprocessor o Pointers Programming Assignment
More informationSWEN-250 Personal SE. Introduction to C
SWEN-250 Personal SE Introduction to C A Bit of History Developed in the early to mid 70s Dennis Ritchie as a systems programming language. Adopted by Ken Thompson to write Unix on a the PDP-11. At the
More informationFile 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
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 9 Pointer Department of Computer Engineering 1/46 Outline Defining and using Pointers
More informationArrays 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
More informationPrinceton University COS 333: Advanced Programming Techniques A Subset of C90
Princeton University COS 333: Advanced Programming Techniques A Subset of C90 Program Structure /* Print "hello, world" to stdout. Return 0. */ { printf("hello, world\n"); -----------------------------------------------------------------------------------
More informationWeek 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430
Week 2 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430 1 Why is the Shell Important? Shells provide us with a way to interact with the core system Executes programs on
More informationArrays 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
More informationCS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code
CS102: Standard I/O Our next topic is standard input and standard output in C. The adjective "standard" when applied to "input" or "output" could be interpreted to mean "default". Typically, standard output
More informationCSE 374 Midterm Exam 11/2/15 Sample Solution. Question 1. (10 points) Suppose the following files and subdirectories exist in a directory:
Question 1. (10 points) Suppose the following files and subdirectories exist in a directory:.bashrc.emacs.bash_profile proj proj/data proj/data/dict.txt proj/data/smalldict.txt proj/notes proj/notes/todo.txt
More informationCSCI565 Compiler Design
CSCI565 Compiler Design Spring 2011 Homework 4 Solution Due Date: April 6, 2011 in class Problem 1: Activation Records and Stack Layout [50 points] Consider the following C source program shown below.
More informationECE264 Spring 2014 Exam 2, March 11, 2014
ECE264 Spring 2014 Exam 2, March 11, 2014 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.
More informationCSC 543 Multiprocessing & Concurrent Programming, Fall 2016
CSC 543 Multiprocessing & Concurrent Programming, Fall 2016 Dr. Dale E. Parson, Midterm Exam Project, Assorted Thread Synchronization Problems This assignment is due by 11:59 PM on Wednesday November 2
More informationArrays and Pointers (part 2) Be extra careful with pointers!
Arrays and Pointers (part 2) CSE 2031 Fall 2011 23 October 2011 1 Be extra careful with pointers! Common errors: Overruns and underruns Occurs when you reference a memory beyond what you allocated. Uninitialized
More informationCS201: Lab #4 Writing a Dynamic Storage Allocator
CS201: Lab #4 Writing a Dynamic Storage Allocator In this lab you will write a dynamic storage allocator for C programs, i.e., your own version of the malloc, free and realloc routines. You are encouraged
More informationC BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.
C BOOTCAMP DAY 2 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Pointers 2 Pointers Pointers are an address in memory Includes variable addresses,
More informationMemory. What is memory? How is memory organized? Storage for variables, data, code etc. Text (Code) Data (Constants) BSS (Global and static variables)
Memory Allocation Memory What is memory? Storage for variables, data, code etc. How is memory organized? Text (Code) Data (Constants) BSS (Global and static variables) Text Data BSS Heap Stack (Local variables)
More informationProgramming and Data Structure
Programming and Data Structure Sujoy Ghose Sudeshna Sarkar Jayanta Mukhopadhyay Dept. of Computer Science & Engineering. Indian Institute of Technology Kharagpur Spring Semester 2012 Programming and Data
More informationChapter 11 Introduction to Programming in C
C: A High-Level Language Chapter 11 Introduction to Programming in C Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University Gives
More informationLesson 5: Functions and Libraries. EE3490E: Programming S1 2018/2019 Dr. Đào Trung Kiên Hanoi Univ. of Science and Technology
Lesson 5: Functions and Libraries 1 Functions 2 Overview Function is a block of statements which performs a specific task, and can be called by others Each function has a name (not identical to any other),
More informationgcc hello.c a.out Hello, world gcc -o hello hello.c hello Hello, world
alun@debian:~$ gcc hello.c alun@debian:~$ a.out Hello, world alun@debian:~$ gcc -o hello hello.c alun@debian:~$ hello Hello, world alun@debian:~$ 1 A Quick guide to C for Networks and Operating Systems
More informationTopic 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
More informationUNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING
UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING APS 105 Computer Fundamentals Final Examination December 16, 2013 2:00 p.m. 4:30 p.m. (150 minutes) Examiners: J. Anderson, B. Korst, J.
More informationCourse organization. Course introduction ( Week 1)
Course organization Course introduction ( Week 1) Code editor: Emacs Part I: Introduction to C programming language (Week 2-9) Chapter 1: Overall Introduction (Week 1-3) Chapter 2: Types, operators and
More informationCSE 333 Midterm Exam July 24, Name UW ID#
Name UW ID# There are 6 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes,
More informationHigh Performance Programming Programming in C part 1
High Performance Programming Programming in C part 1 Anastasia Kruchinina Uppsala University, Sweden April 18, 2017 HPP 1 / 53 C is designed on a way to provide a full control of the computer. C is the
More informationChapter 11 Introduction to Programming in C
Chapter 11 Introduction to Programming in C C: A High-Level Language Gives symbolic names to values don t need to know which register or memory location Provides abstraction of underlying hardware operations
More informationECE264 Spring 2013 Exam 1, February 14, 2013
ECE264 Spring 2013 Exam 1, February 14, 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.
More informationC Tutorial. Pointers, Dynamic Memory allocation, Valgrind, Makefile - Abhishek Yeluri and Yashwant Reddy Virupaksha
C Tutorial Pointers, Dynamic Memory allocation, Valgrind, Makefile - Abhishek Yeluri and Yashwant Reddy Virupaksha CS 370 - Operating Systems - Spring 2019 1 Outline What is a pointer? & and * operators
More information