Link to Dr. T homepage CSE1320 textbook drawing

Information for CSE1320
Intermediate Programming with C

This page has links to various documents for students of CSE1320 in Dr. Tiernan's section. This is the PRIMARY reference location for class material. Dr. T does not hand out much paper in class any more but feel free to print material you find on this website.

There is much material about how to turn in lab assignments in this class, how to use omega, tips on writing functions, and bits of info about challenging things in C. ** USE IT.** Other material posted here includes old test materials and links outside UTA to related and useful sites. There are also links to UTA and other sites with information on the vi editor, the pico editor, on Unix systems, and OIT information.

Those lectures that have been captured to the web are linked on the lecture capture page.

    Read your textbook and bring it to class!

    Lab #5 Assignment for Spring 2011 - REVISED and SIMPLIFIED as web page and as MS Word doc

            Please report any errors or typos in assignment to Dr. T by e-mail ASAP.

            Lab #5 DESIGN DOCUMENT DUE Thursday, May 5 at 12:00noon.
            Lab #5 Design Document must be submitted on time in order for Lab #5 assignment to be graded.
            Submit Design Document to assigned TA (see info in the table below)

                  Contact Dr. T in case of problems.

            Lab #5 DUE Thursday, May 12th at 8pm. NO EXCEPTIONS!
            See lab assignment for extra credit early deadlines.

            Submit Lab to assigned TA (see info in the table below)
                  See lab submission instructions below
                  Posted Apr. 29, 7:00pm


Small modification to 'line-of-data' input method for Lab #2       The Lab #2 instructions say that you should read in the data from the line "within a single input command". I am amending this to say that you should read the data from the line "using a minimum number of input commands". This means that if you can read multiple pieces of data at once, then you should do so but that you do not have to do it all in one command. This allows you to use a loop to read leg data if desired. I believe that you would be able to read the whole line of input with three scanf commands, one of which reads up through the number of legs, one of which is inside a loop to read the leg data, and the last to read all the data after the leg data.
Notes on errors reading chars with scanf and %c:

This is a classic C error in input.

      When C reads in data, it actually does not read each key directly. It reads the entered keystrokes that are saved in the input buffer. You've seen this when you were working on something, the screen seemed to stop but you kept typing, and when the screen unfroze it printed out all the things you had typed while it was frozen. Those keystrokes you typed went into an input buffer. C doesn't accept an input until you have pressed the enter key which also goes into the buffer.
      When C is trying to read numbers (%d, %f, etc) for input from the input buffer, it will ignore any whitespace characters it sees until it finds a letter or a number. A letter will make it act weird and a number will make it act OK. A whitespace char is anything that doesn't normally print a character to the screen when you type it like the space key, the enter key, the tab key, etc.
      However, when C is trying to read a char (%c) EVERY KEY THAT IS TYPED is a char. That means that any keystroke sitting in the input buffer is a char and C will read it when you use %c. AND, since C doesn't accept any input until an enter key is typed then the input buffer almost always has an enter key in it from the previous thing you read. Therefore, when you try to read a %c, it looks at the input buffer, sees a char (the enter key) and reads it. When you print it, it is blank.
So there are two simple fixes I usually recommend.

Fix 1:
      getchar(); //reads one char from input buffer
      printf("Enter whatever...");
      scanf("%c",&mychar);

or Fix 2:
      printf("Enter whatever...");
      scanf("%c %c",&mychar,&mychar ); //reads two chars and stores in same place so second overwrites the first


Notes on C strings:

Strings in C are just character arrays. To declare the array for the strings you declare it as type char. I recommend that you read the name into a temp array (char dest_input[100]), check the length with the strlen command, and then copy arrays that are 40 chars or less to the 2-D string array (char travelname[TRIPMAX][NAMEMAX]) with the command strcpy. The strlen and strcpy commands are in string.h.
The following pieces of code would be used in your program:

      #include (angle bracket) string.h (angle bracket)      //to get the string commands. Replace (angle bracket) with the symbol - HTML doesn't like to print it.
      // declarations of constants TRIPMAX (6) and NAMEMAX (40)
      //... other stuff here

      char travelname[TRIPMAX][NAMEMAX];
      char dest_in[100];      //temp array to hold name when reading
      int tripnum;            // variable used as counter for current trip
      //... other stuff here

      scanf("%s",dest_in);      //yes, just the name of the array
      if (strlen(dest_in) < NAMEMAX)
            strcpy(travelname[tripnum],dest_in);      //yes, just like this

Both strlen and strcpy need the location of the array as input. Therefore if we pass in the name of the array then we are passing in the address, i.e. the location, of the array. That's why we don't use the [ ] and why we don't need the & operator.


Notes on fractional parts being exact when working with HH.MM:

When using HH.MM and trying to extract the MM component as an integer you may have tried to calculate minutes with:
      int hrs = hhmm; // assuming hhmm is the float with the value HH.MM
      int min = (hhmm - hrs) * 100;
but gotten the wrong value, for example if hhmm was 3.05 you might have gotten min = 4.
Basically, the problem is that floats are stored in binary so they aren't exact as decimal values. For example, .05 might be stored as .049999999999999999 . Therefore, sometimes the value of a fraction doesn't end up as expected. So, to work around this a simple strategy is that instead of:
      minutes = ((time - hours) * 100;
use this:
      minutes = time * 100 - hours * 100;
and it will typically solve the problem.


 
Completed:
Lab #1 Assignment for Spring 2011 as web page
Lab #2 Assignment for Spring 2011 as web page
Lab #3 Assignment for Spring 2011 as web page
Lab #4 Assignment for Spring 2011 as web page

 

CSE1320 Syllabus
CSE1320 Syllabus Word doc
Posted 23 Dec 2010; Revised 17 Jan 2011

CSE 1320 Schedule
CSE 1320 Schedule Excel file
Posted Dec 23 2010

Ethics statement
If you did not sign this in class, then print it on one page, sign, and bring to the next class


If you have trouble reading something on this website or
if you find a broken link or other problem
please e-mail Dr. Tiernan

Section:
Section 002 - Dr. Tiernan CSE Help Desk
TA:
Azade Nazi Various
For questions, e-mail:
azadenazi.uta@gmail.com N/A
For lab submissions,send to:
azadenazi.uta@gmail.com N/A
Office Hours:
Mon., Tues., and Wed. 1pm - 2pm Thurs noon - 3pm;
Fri noon - 6pm;
Sat noon - 6pm;
Location: ERB 426 (the new Engineering Research Building) ERB 125 (The new Engineering Research Building)

green yellow neon Reference material for Lab Assignments green yellow neon

How to submit your 1320 Lab - including script file info
     Updated Dec. 2010
     Lab Assignment Submission Information for Dr. Tiernan's section of CSE 1320

green yellow neon

Miscellaneous Coding Tidbits

Links to information about using 'getline' instead of 'gets':
    
GNU C Manual - Line-Oriented Input
     GNU C Programming Tutorial - getline

To get input from data files:
     Include stdio.h as a header file, declare a FILE * variable, use fopen to connect the FILE * variable to your physical file. See references further below for C file I/O examples.
To deal with reading strings correctly from files:
     When reading a string after reading a number from a file, you may need to read a junk character out between reading the number and the string. Use the getc(file_pointer) command to read one character from a file. If one doesn't work try using two getc commands.
To compile multiple physical files into a single program:
     To compile two files (Ex: L41.c and L42.c) together into a single program, use the gcc command with both file names following. Example:
     myomega>gcc L41.c L42.c
To get time and date information for your program using C functions:
     Information and an example using localtime(), time(), and the struct tm are available at www.cplusplus.com/ref/ctime/localtime.html Click on the various links to see the struct definition and other examples

Coding and Other Tips for Lab Assignments in CSE1320

Dr. Brezeale's handy-dandy notes on moving from Python to C (see the Misc. section)

Links to information about C file I/O:
Reference from Boston University CS class
C File I/O
Use section "2. C FIle I/O". Ignore section "1. Redirection".

Reference from University of Essex
File I/O, fopen and fclose
Clearly written with examples

green yellow neon CSE1320 Powerpoint presentations green yellow neon

Software Engineering Slide Presentation
The above link is for a Powerpoint presentation on Software Engineering that will be presented at the beginning of the semester.

Beginner's guide to writing a C function
Reference card for C commands to keep handy while you start writing functions

Intro to omega
Covers how to connect to omega, a few Unix commands, a short list of editors and compilers and an example of using the GDB debugger which is available for gcc.
A Powerpoint presentation by Do Kim (CSE senior) edited by Dr. T.
Posted 31 August 2004

Reference card for UNIX commands to use on omega

This has hints about control structures, variable types, arrays, structs, pointers, linked lists, recursion and DEBUGGING!
Sticky Bits in C online presentation
Sticky Bits in C to download
A Powerpoint presentation by Dr. T.
Posted 19 April 2004

green neon

Example Quiz

2nd Example Quiz with solutions

Sample Test Questions with Comments

Below is a link to the review sheets and tests that were given for previous C classes. Similar reviews will be posted for this semester.

Tests, test reviews, and old lab assignments for previous C 1320 classes taught by Dr. Tiernan

Example Ethics Policy

green yellow neon

These links go to various resources for Unix, the vi editor, and the emacs editor. There is also a link to the main OIT web page for questions about UTA's systems.

Picture of a frog

   "how-to" Unix reference manual from UTA OIT
   - be sure to scroll down to the bottom of the OIT page if no Unix guide
   info is visible to the right of the menu bar

   vi Unix editor reference from UTA OIT
   - be sure to scroll down to the bottom of the OIT page if no vi editor
   info is visible to the right of the menu bar

   vi Unix editor reference: University of Washington

   vi Unix editor tutorial: University of Hawaii

   emacs Unix editor reference manuals: GNU organization

   pico Unix editor reference from the University of Michigan

   pico Unix editor reference from the University of Chicago

   OIT - Office of Information Technology website which has other helpful links


Copyright Tyger Design, Inc. Web page created by Tyger Design.