Pointers Project
COP-3223H
Table of Contents
1. Overview
In this project, you will implement a linked list and several functions that operate on them.
2. Repository setup
Log into eustis:
ssh NID@eustis.eecs.ucf.edu
Go to your local repository: Be sure you have already completed the git exercise before attempting this project.
cd ~/cop3223spring26/assignments
Create and enter a directory for the pointers project:
mkdir pointers cd pointers
You only need to mkdir once to create the directory.
Make sure you are in the right directory
pwd
You should see
/home/net/NID/cop3223spring26/assignments/pointers
3. Create the pointers project
Make sure you are in the right directory
pwd
You should see
/home/net/NID/cop3223spring26/assignments/pointers
3.1. The linked list template program
wget https://www.cs.ucf.edu/~gazzillo/teaching/cop3223hspring26/files/template.c mv template.c pointers.c
#include <stdio.h>
#include <assert.h>
#include <malloc.h>
#include <stddef.h>
#include <stdbool.h>
struct list {
int data;
struct list *next;
};
struct list *add(struct list *head, int data) {
struct list *newlink;
newlink = malloc(sizeof(struct list));
newlink->data = data;
newlink->next = head;
return newlink;
}
void print(struct list *head) {
if (NULL == head) {
printf("()");
} else {
printf("(%d,", head->data);
print(head->next);
printf(")");
}
}
void deleteall(struct list *head) {
if (NULL == head) {
// do nothing
} else {
deleteall(head->next);
free(head);
}
}
// get the length of the list, 0 if NULL
int len(struct list *head) {
// TODO
}
// return the list element that contains data or NULL if none
struct list *get(struct list *head, int data) {
// TODO
}
// return head or next if head is being deleted or NULL if empty going in or out
struct list *del(struct list *head, int data) {
// TODO
}
int main(int argc, char **argv) {
struct list *head;
bool done = false;
head = NULL;
do {
char c;
int value;
int retval;
printf("enter a command (type h for help): ");
retval = scanf(" %c", &c);
done = done || EOF == retval;
/* printf("command: %c\n", c); */
switch (c) {
case 'p':
printf("current list: ");
print(head);
printf("\n");
break;
case 'a':
printf("enter an integer value: ");
retval = scanf("%d", &value);
done = done || EOF == retval;
head = add(head, value);
break;
case 'l':
printf("length: %d\n", len(head));
break;
case 'g':
printf("enter an integer value: ");
retval = scanf("%d", &value);
done = done || EOF == retval;
printf("found list: ");
print(get(head, value));
printf("\n");
break;
case 'd':
printf("enter an integer value: ");
retval = scanf("%d", &value);
done = done || EOF == retval;
head = del(head, value);
printf("new list: ");
print(head);
printf("\n");
break;
case 'D':
deleteall(head);
head = NULL;
printf("deleted all\n");
break;
case 'h':
printf("instructions:\n");
printf("p - print the list\n");
printf("a - add a link\n");
printf("l - report the current length\n");
printf("g - get a link\n");
printf("d - delete a link\n");
printf("D - delete the whole list\n");
printf("h - help\n");
printf("q - quit\n");
break;
case 'q':
done = true;
break;
default:
printf("invalid command\n");
break;
}
} while (! done);
printf("bye!\n");
}
3.2. Example inputs and outputs
Here is a complete sessions that uses all the features.
enter a command (type h for help): a enter an integer value: 4 enter a command (type h for help): a enter an integer value: 43 enter a command (type h for help): a enter an integer value: 87 enter a command (type h for help): a enter an integer value: 78 enter a command (type h for help): p current list: (78,(87,(43,(4,())))) enter a command (type h for help): l length: 4 enter a command (type h for help): g enter an integer value: 78 found list: (78,(87,(43,(4,())))) enter a command (type h for help): d enter an integer value: 78 new list: (87,(43,(4,()))) enter a command (type h for help): p current list: (87,(43,(4,()))) enter a command (type h for help): D deleted all enter a command (type h for help): l length: 0 enter a command (type h for help): a enter an integer value: 1 enter a command (type h for help): p current list: (1,()) enter a command (type h for help): q bye!
3.3. Program name
The program must be called pointers.c and must be in the pointers directory, i.e., the full path should be
~/cop3223spring26/assignments/pointers/pointers.c
Compile and run the program whenever you make changes using
cd ~/cop3223spring26/assignments/pointers/ gcc -o pointers pointers.c ./pointers
Be sure there is no other output besides the required output as the grading will be automatic. If you would like to have debugging output, use fprintf(stderr, "...", ...); instead of printf.
4. Submitting your program via git
This assumes you have already setup your repository and that you are still in your hello directory in your repository.
4.1. Add and commit the file
Enter
git add pointers.c git commit pointers.c
Write an appropriate commit message. Remember that you will need to save (Ctrl-x Ctrl-s) then quit (Ctrl-x Ctrl-c) the emacs editor that pops up. If you are having trouble, be sure that you have completed the git project first.
Do not commit the backup file pointers.c~ nor the pointers program. Use a .gitignore file to exclude those from the repository, so they won't show up when you type git status.
Then to synchronize the changes to the remote git repository on the grading server:
git push
5. Self-check
5.1. Remove the previous self-check
If you have already run the self-check, you can remove it like this
rm -rf ~/tmp/assignments_selfcheck
Double-check the path carefully to avoid deleting the wrong directory.
5.2. Make a fresh clone of your project
git clone gitolite3@eustis3.eecs.ucf.edu:cop3223/$USER/assignments ~/tmp/assignments_selfcheck
You should see something like
Cloning into '/home/net/NID/tmp/assignments_selfcheck'... Welcome to eustis.eecs.ucf.edu. Please use your NID and NID password to log in. See http://t.cs.ucf.edu/help/eustis for additional instructions. remote: Enumerating objects: 16, done. remote: Counting objects: 100% (16/16), done. remote: Compressing objects: 100% (12/12), done. remote: Total 16 (delta 1), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (16/16), done. Resolving deltas: 100% (1/1), done.
If you see
fatal: destination path '/home/net/NID/tmp/assignments_selfcheck already exists and is not an empty directory.
5.3. Enter the fresh clone's directory
cd ~/tmp/assignments_selfcheck/pointers
5.4. Make sure pointers runs correctly
cd pointers gcc -o pointers pointers.c ./pointers
6. Grading schema
| Criterion | Points |
|---|---|
| pointers.c exists and compiles | 1 |
| The program runs correctly, prorated by successful test cases | 3 |
| TOTAL | 4 |