cse220-s09-p02-rubric - CSE220 Programming for Computer...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE220 Programming for Computer Engineering Lab Project 2: 27 Points Spring 2009 ~ Burger ~ Dept. of CS & Engineering ~ Arizona State University Page 1 You may work in pairs with a partner on this lab project if you wish or you may work alone . If you work with a partner, only hand in one lab report with both of your names on it; you will each earn the same number of points. The deadline for this lab project is 4:00am on Sat 14 Feb (Happy Valentine's Day!) Consult the online syllabus for the late and academic integrity policies. Lab Project Objectives 1. Practice I/O redirection using <, >, and |. 2. Become familiar with filename globbing, wildcards * and ?. 3. Use the GCC C compiler to compile a C program. 4. Write simple Bash shell scripts involving variable assignments, expr and seq commands, and for loops. This project is written assuming you are using an account on research.asu.edu which is running RedHat GNU/Linux. You may also use the GNU/Linux machines in the Brickyard Engineering Computer Lab which are running CentOS ( http://www.centos.org ), or your own home computer with whichever GNU/Linux distribution you happen to have installed. 1. (3 pts) Log in to research.asu.edu or some other GNU/Linux system. Using VI or some other text editor, enter the code for this C program and save it in a file named p02-01.c : /* p02-01.c */ #include <stdio.h> int main() { char ch; while ((ch = getchar()) > 0) { putchar(ch); if (ch != '\n') putchar(ch); } return 0; } The char getchar() 1 function reads a character from stdin (which is the keyboard by default) and returns a negative integer val- ue when ^D (Ctrl+D) is read 2 . The void putchar(char) 3 function sends a character to stdout (which is the console window by default). Therefore, this program just redisplays every string that is typed in, but with the characters duplicated 4 , as shown be- low. Compile this program using the GNU C compiler command, ~/asu/cse220 $ gcc p02-01.c –o p02-01 Then run this program to verify that it works correctly for you and once you are sure, run the program again but this time use the I/O redirection symbols < and > to redirect stdin from the keyboard to the file /etc/passwd and redirect stdout from the console window to the file passwd.copy in the current directory. 1 Help on many C functions is available through a man page: try man getchar; or http://www.cplusplus.com/reference/clibrary/cstdio/getchar.html . The getchar() function performs buffered I/O, i.e., characters that are typed at the keyboard are placed into an input buffer (or input queue) until the '\n' character is encoun- tered. Then an internal read pointer is set to point to the character in the front of the buffer. Every time getchar() is called, the character that is returned is the cha- racter in the buffer pointed to by the read pointer. After reading that character, the character is removed from the buffer and the internal read pointer is updated to point to the next character in the buffer. Once all the characters have been read from the buffer, the system will wait again for you to type in a string and enter
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

cse220-s09-p02-rubric - CSE220 Programming for Computer...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online