Work

We will be submitting all assignments as submodules. I will provide a GitHub link for the main repository with each assignment. When creating your submodules, use the following naming convention: 
  • lastF0f1f2, e.g. dyrland-weaverJon
  • For multiple person assignments, use the same convention with an _ between names, use the earlier alphabetical name first. e.g. brooksPet_dyrland-weaverJon

Work 07: Get Argumentative

posted Nov 26, 2019, 5:42 AM by JonAlf Dyrland-Weaver   [ updated Nov 26, 2019, 6:52 AM ]


strep is a function in string.h used to help parse strings
  • strsep( <SOURCE>, <DELIMETER> )
  • Locates the first occurrence of any character in the DELIMITER string and replaces it with NULL
  • Returns the beginning of the original string
  • sets the source string pointer  to point to the index 1 byte after the location of the new NULL
  • Since the source variable's value is changed, it must be a pointer to a string.
  • To test it out, try the following code:
  • char line[100] = "woah-this-is-cool";
    char *s1 = line;
    printf("[%s]\n", strsep( &s1, "-" ));
    printf("[%s]\n", s1);

Write a function that uses strep to parse a line of arguments
  • Use the following header: char ** parse_args( char * line );
  • It should take a string with the command line invocation of a program (like "ls -a -l")
    • Note that there is a " " between each argument
  • Return an array of pointers to each individual argument in the parameter string, that could be used for execvp()
  • For example, the following code should work (assuming all variables are declared appropriately:
    • char ** args = parse_args( line );
      execvp(args[0], args);
  • You can make the following assumptions:
    • There is only 1 space between each argument in the original string
    • The original string contains no more than 5 arguments
    • The original string is correctly formatted

github link: https://github.com/mks65/parse_args.git

Work 06: Please Follow the Dir[ections]

posted Nov 15, 2019, 6:39 AM by JonAlf Dyrland-Weaver   [ updated Nov 18, 2019, 8:05 AM ]

New and improved instructions:
  • Your program should handle user input as follows:
    • If a command line argument is entered, use that as the directory to scan.
    • If not, the program should ask the user to enter a directory to scan.
    • In either case, don't assume your user knows what they are doing, if an invalid directory is entered, take reasonable action (*ahem* errno *cough cough*)
Write a program that will gather various information about a directory, specifically:
  • list all the files in the directory
  • specify which files are directories (if any)
  • show the total size of all the regular files the directory
    • note that you do not have to recursively go through any subdirectories to find their size for this part (unless you want to, but that is not a simple task)
  • Have the program scan the current directory
  • Possible enhancements:
    • Recursively list the files in any subdirectories, update the total to include the total size of subdirectories
    • Print out the size in a more readable format (like using KB, MB, GB for -byte prefixes)
    • Make it look more like $ ls -l

Github link:
https://github.com/mks65/dirinfo.git

Below is sample output, yours may differ, but as long as it presents the information requested above you will receive full credit.
$ ./a.out
Statistics for directory: .
Total Diectory Size: 13453 Bytes
Directories:
        .
        ..
Regular files:
        a.out
        dirinfo.c
        dirinfo.c~
        dirstuff.c
        dirstuff.c~

$ ./a.out
Statistics for directory: .
Total Diectory Size: 17766 Bytes
Directories:
        .
        ..
        dir
        structRW
Regular files:
        a.out
        error.log
        filelist
        files.c
        read.c
        ReadTest
        redirect.c
        redirect.c~
        redirect_full.c
        redirect_full.c~
        redirTest
        statfiles.c
        statfiles.c~
        write.c
        WriteTest

Work 05: I Need Information, STAT!

posted Nov 13, 2019, 7:02 AM by JonAlf Dyrland-Weaver   [ updated Nov 13, 2019, 7:38 AM ]

There is a function called stat. It is used to get information about a file. Write a program that uses stat to display the following information about a file:
  • file size
  • mode (permissions)
  • time of last access (displayed in the following format: Fri Oct 28 09:03:01 2016
  • Note
    • You may hardcode the file that your program uses, make sure the program works when I download and run it.
    • If only there were some file that you know I will have and where it is... hmm...
Once you have that, try the following:
  • Modify the size so it is printed out in human readable form (that is using B, KB, MB, GB).
    • You may want to look into the sprintf function to help.
  • Attempt to print out the permissions in ls -l form, ignoring the early bits that include the file type information
    • Permissions are of type mode_t, which is an integer type.
    • The permissions section of the mode is stored in the last 9 bits of the mode_t data type.

Github clone url:
https://github.com/mks65/stat.git

Work 04: /dev[ise a]/random plan

posted Nov 8, 2019, 6:44 AM by JonAlf Dyrland-Weaver

Write a c program with the following features:
  1. A function that generates a random number by reading in the correct number of bytes from /dev/random.
  2. A main function that:
    1. Populates an array with 10 random numbers generated by your random function (print out each value)
      • If your program seems to stall at this step, it's possible that your computer doesn't have enough entropy and is waiting, you can read from /dev/urandom instead.
    2. Writes the array to a file
      • Do not use a loop when writing to the file
    3. Reads that file into a different array
      • Do not use a loop when reading from the file
    4. Prints out the contents of the second array to verify the random numbers are the same from step 1
  • Remember to use good practices, like checking return values for errors
  • Also remember to include a makefile that includes a separate run target 
github clone links
https://github.com/mks65/randfile.git
 
Sample output:
Generating random numbers:
        random 0: 198116400
        random 1: 2592608753
        random 2: 2833624368
        random 3: 3273750590
        random 4: 3548697368
        random 5: 3876828898
        random 6: 2617393183
        random 7: 1720936907
        random 8: 682596330
        random 9: 2411695830

Writing numbers to file...

Reading numbers from file...

Verification that written values were the same:
        random 0: 198116400
        random 1: 2592608753
        random 2: 2833624368
        random 3: 3273750590
        random 4: 3548697368
        random 5: 3876828898
        random 6: 2617393183
        random 7: 1720936907
        random 8: 682596330
        random 9: 2411695830

Work 03: Enlist Your C Skillz

posted Oct 23, 2019, 7:20 AM by JonAlf Dyrland-Weaver   [ updated Oct 25, 2019, 7:37 AM ]

This will be due Monday (10/28) morning.

Write a simple linked list program. You will need a define a node struct with the following data members:
  • A piece of data (your choice)
  • A pointer to the next node
  • Here's an example of what the struct could look like:
    • struct node { int i; struct node *next; };
Create the following functions:
  • void print_list(struct node *);
    • Should take a pointer to a node struct and print out all of the data in the list
  • struct node * insert_front(struct node *, int);
    • Should take a pointer to the existing list and the data to be added, create a new node and put it at the beginning of the list.
    • The second argument should match whatever data you contain in your nodes.
    • Returns a pointer to the beginning of the list.
  • struct node * free_list(struct node *);
    • Should take a pointer to a list as a parameter and then go through the entire list freeing each node and return a pointer to the beginning of the list (which should be NULL by then).  
  • struct node * remove_node(struct node *front, int data);
    • Remove the node containing data from the list pointed to by front.
    • If data is not in the list, nothing is changed.
    • Returns a pointer to the beginning of the list.
  • Your list functions should be in a .c/.h library, with a separate .c file used for testing.              
Don't forget to test out these various functions to ensure they work correctly. (Just to be clear, when you run the program and get "Segmentation fault" that means it's not working.). Here is a sample run that shows things being tested:

$ ./test_list 
Printing empty list:
[ ]
Adding #s 0-9 to list.
Printing list:
[ 9 8 7 6 5 4 3 2 1 0 ]
Removing 9:
[ 8 7 6 5 4 3 2 1 0 ]
Removing 4:
[ 8 7 6 5 3 2 1 0 ]
Removing 0:
[ 8 7 6 5 3 2 1 ]
Removing -1:
[ 8 7 6 5 3 2 1 ]
Freeing list.
freeing node: 8
freeing node: 7
freeing node: 6
freeing node: 5
freeing node: 3
freeing node: 2
freeing node: 1
Printing list:
[ ]


Github link:
https://github.com/mks65/list.git

Work 02: Construction

posted Oct 15, 2019, 7:17 AM by JonAlf Dyrland-Weaver   [ updated Oct 15, 2019, 10:58 AM ]


This is due Thursday Morning (10/17)
  • Create a struct that has at least 2 data members, one must be a string.
    • You can provide struct prototypes outside of functions.
    • Don't just combine random things, make it meaningful (like food and price, athlete and associated statistic, Pokemon and something about Pokemon ..)
  • Write a function that returns an example of your struct when run.
    • This should not return the same values every time.
  • Write a function that prints out variables of your structs type in a reasonable way.
  • Write a function that modifies values of your struct's type.
  • Write a main function that tests all these things.
    • Have meaningful output.
  • DONT FORGET A MAKEFILE
GitHub clone link: https://github.com/mks65/construction.git

Submodule Bonanza!

posted Oct 10, 2019, 7:15 AM by JonAlf Dyrland-Weaver

Add your previous assignments using submodules, please have this done by Saturday morning.

  • Euler: https://github.com/mks65/euler.git
  • Array_swap: https://github.com/mks65/array_swap.git
  • Make: https://github.com/mks65/make.git
  • Strings: https://github.com/mks65/strings.git

Work 01: String Assignment Addendum

posted Oct 6, 2019, 5:02 PM by JonAlf Dyrland-Weaver

  • Look at the two files here: https://github.com/mks65/dwsource/tree/master/strings
    • One is the main.c file I used to test my own string functions. If you had trouble with your string tests, look at this and update your own tests.
    • The other is the makefile. Notice the run and clean targets. Makefiles targets don't actually need dependencies, and the rules can be any series of shell commands. It is common for makefiles to have targets that serve similar purposes to run and clean. Run is especially helpful since I will be able to test all your work by doing the following:
      • $ make
      • $ make run
    • Please update your makefiles to at least contain a run target.

Work 00

posted Sep 4, 2019, 9:40 AM by JonAlf Dyrland-Weaver

Fill out the following survey: https://forms.gle/TVpGMyKN3UGqtHC88

1-9 of 9