User Tools

Site Tools


haas:summer2017:cprog:projects:sfa0

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
haas:summer2017:cprog:projects:sfa0 [2017/07/26 15:11] wedgehaas:summer2017:cprog:projects:sfa0 [2017/07/26 15:59] (current) – [Methods of file access] wedge
Line 167: Line 167:
   * close   * close
  
-We'll be specifically focusing on opening, reading, and closing files for this project.+We'll be specifically focusing on opening, reading, writing, and closing files for this project.
  
 A point of distinction on "write" vs. "append": when you open a file for writing, you start from its beginning, overwriting and existing content; when you open for appending, you start at its end, adding to (appending) existing content. A point of distinction on "write" vs. "append": when you open a file for writing, you start from its beginning, overwriting and existing content; when you open for appending, you start at its end, adding to (appending) existing content.
Line 231: Line 231:
     fscanf(fp, "%hu", &value);     fscanf(fp, "%hu", &value);
 </code> </code>
 +
 +====When the data ends: End of File checking====
 +When you are reading from a file and have exhausted its contents, the last character read from the file should be a special EOF symbol, and various other status bits are likely flipped in our FILE pointered struct to indicate that the end of file has been reached.
 +
 +A good function to use is **feof()**, which takes a FILE pointer to check, and it will return a nonzero value if the end of file has been reached (great for using in selection statements or loops as a combined check and termination combo!)
  
 ====Responsible file access==== ====Responsible file access====
Line 249: Line 254:
 For this project, mixing together all the skills we've previously learned and just learned is in order. For this project, mixing together all the skills we've previously learned and just learned is in order.
  
-In **/var/public/cprog/sfa0/datafile.db**+In **/var/public/cprog/sfa0/** is a file called **datafile.db**, which contains several records of the following format:
  
 +<code>
 +NAME     # 1S 1T 2S 2T 3S 3T ... #S #T
 +</code>
 +
 +Where:
 +
 +  * the first 8 characters correspond to an ALL UPPERCASE name of an individual (name doesn't have to occupy all 8 characters, but will not exceed 8 characters)
 +  * the # refers to the number of score pairs associated with that individual (will not exceed 127)
 +  * then a set of number pairs (labeled S and T, for Score and Total), that are associated with that individual (individual numbers will not exceed 65535)
 +
 +It will be your task to write a program that:
 +  * opens that file:
 +    * via its absolute path
 +    * for reading
 +  * load the data for each line into a custom struct you've made that contains the following elements:
 +    * place to store the person's name
 +      * store the person's name with a leading Uppercase, but all other characters represented in lowercase; for example: MOANA becomes Moana
 +    * array to store the person's scores
 +    * array to store the corresponding totals for each score
 +    * array to store the average of each score:total pair 
 +    * element to store the tally of all the scores
 +    * element to store the tally of all the totals
 +    * element to store the average of the averages
 +    * element to store the average of the tallied scores:tallied totals
 +  * opens the local file: **sfa0.out** for **writing**
 +  * stores the processed results you have in memory (in your structs), in the following format:
 +
 +<code>
 +Name:#:scoreTally:scoreTotal:avgofAverages:averageofTallies:#s,#t;...;2s,2t;1s,1t
 +</code>
 +
 +Of particular note:
 +
 +  * Name of individual is that changed Uppercase lead-in letter followed by all lowercase
 +  * category fields are separated by colons ':'
 +  * averages should be truncated 2 places after the decimal point
 +    * if rounding occurs, so be it; if not, don't worry about it
 +  * the written out score pairs are done so in reverse order (last to first, although score still precedes total)
 +    * the score is separated from the tally by a comma ','
 +    * the field separators in the score pairs field are semi-colons ';'
 +
 +For example, if the source data was:
 +
 +<code>
 +KRIS    2 13 17 9 18
 +</code>
 +
 +The corresponding line written out to **sfa0.out** would be:
 +
 +<code>
 +Kris:2:22:35:63.25:62.86:9,18;13,17
 +</code> 
 +
 +Additional constraints:
 +  * use FILE pointers and FILE pointer-oriented C library functions (fopen(), fprintf(), fscanf(), fclose())
 +  * close all open files when done
 +  * you must have and use 2 FILE pointers
 =====Review of Compiling/Executing===== =====Review of Compiling/Executing=====
 Just to review the compilation/execution process for working with your source code, if we had a file, **hello.c**, that we wished to compile to a binary called **hello**, we'd first want to compile the code, as follows: Just to review the compilation/execution process for working with your source code, if we had a file, **hello.c**, that we wished to compile to a binary called **hello**, we'd first want to compile the code, as follows:
Line 295: Line 357:
  
 <cli> <cli>
-$ submit cprog fcc0 fcc0.c +$ submit cprog sfa0 sfa0.c sfa0.out 
-Submitting cprog project "fcc0": +Submitting cprog project "sfa0": 
-    -> fcc0.c(OK)+    -> sfa0.c(OK) 
 +    -> sfa0.out(OK)
  
 SUCCESSFULLY SUBMITTED SUCCESSFULLY SUBMITTED
Line 303: Line 366:
  
 You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches. You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.
- 
-What I'll be looking for: 
- 
-<code> 
-78:fcc0:final tally of results (78/78) 
-*:fcc0:project submitted [6/6] 
-*:fcc0:FCC game adequately implemented [6/6] 
-*:fcc0:consistent and relevant commenting [6/6] 
-*:fcc0:consistent indentation [6/6] 
-*:fcc0:output consistent with project specifications [6/6] 
-*:fcc0:compiles with no messages generated [6/6] 
-*:fcc0:correct operation (run 1/4) [6/6] 
-*:fcc0:correct operation (run 2/4) [6/6] 
-*:fcc0:correct operation (run 3/4) [6/6] 
-*:fcc0:correct operation (run 4/4) [6/6] 
-*:fcc0:intro function works and used [6/6] 
-*:fcc0:display function works and used [6/6] 
-*:fcc0:chkmove function works and used [6/6] 
-</code> 
haas/summer2017/cprog/projects/sfa0.1501081901.txt.gz · Last modified: by wedge