diff --git a/handouts/Lab-Structs-Worksheet.pdf b/handouts/Lab-Structs-Worksheet.pdf deleted file mode 100644 index 7f5c233..0000000 Binary files a/handouts/Lab-Structs-Worksheet.pdf and /dev/null differ diff --git a/handouts/Lab-Structs-Worksheet.tex b/handouts/Lab-Structs-Worksheet.tex deleted file mode 100755 index 3514208..0000000 --- a/handouts/Lab-Structs-Worksheet.tex +++ /dev/null @@ -1,95 +0,0 @@ -\documentclass[10pt]{exam} -%\printanswers -\usepackage{fullpage} - -\setlength{\parindent}{0pt} -\setlength{\parskip}{.25cm} - -\usepackage{graphicx} - -\usepackage{xcolor} - -\definecolor{darkred}{rgb}{0.5,0,0} -\definecolor{darkgreen}{rgb}{0,0.5,0} -\usepackage{hyperref} -\hypersetup{ - letterpaper, - colorlinks, - linkcolor=red, - citecolor=darkgreen, - menucolor=darkred, - urlcolor=blue, - pdfpagemode=none, - pdftitle={Lab 11.0 - Encapsulation - Worksheet}, - pdfauthor={Christopher M. Bourke} - pdfkeywords={} -} - -\definecolor{MyDarkBlue}{rgb}{0,0.08,0.45} -\definecolor{MyDarkRed}{rgb}{0.45,0.08,0} -\definecolor{MyDarkGreen}{rgb}{0.08,0.45,0.08} - -\definecolor{mintedBackground}{rgb}{0.95,0.95,0.95} -\definecolor{mintedInlineBackground}{rgb}{.90,.90,1} - -%\usepackage{newfloat} -\usepackage[newfloat=true]{minted} -\setminted{mathescape, - linenos, - autogobble, - frame=none, - framesep=2mm, - framerule=0.4pt, - %label=foo, - xleftmargin=2em, - xrightmargin=0em, - startinline=true, %PHP only, allow it to omit the PHP Tags *** with this option, variables using dollar sign in comments are treated as latex math - numbersep=10pt, %gap between line numbers and start of line - style=default, %syntax highlighting style, default is "default" - %gallery: http://help.farbox.com/pygments.html - %list available: pygmentize -L styles - bgcolor=mintedBackground} %prevents breaking across pages - -\setmintedinline{bgcolor={mintedBackground}} -\setminted[text]{bgcolor={mintedBackground},linenos=false,autogobble,xleftmargin=1em} -%\setminted[php]{bgcolor=mintedBackgroundPHP} %startinline=True} -\SetupFloatingEnvironment{listing}{name=Code Sample} -\SetupFloatingEnvironment{listing}{listname=List of Code Samples} - -\begin{document} - -\section*{CSCE 155 - Lab 11.0 - Encapsulation \& Structures - Worksheet} - -Names: \underline{\hspace{10cm}} - -\begin{questions} - -\question Which RSS feed did you choose and what is the most recent - story published through it? - \begin{solution}[3cm] - \end{solution} - -\question How many stories were available on the RSS feed when you - executed your program? - \begin{solution}[3cm] - \end{solution} - - - - - - - -\question Closely examine the description and titles of each of the - RSS items. Do you notice any weird characters or odd formatting? - Can you explain them? - \begin{solution}[3cm] - \end{solution} - -\question Demonstrate your working programs to a lab instructor. - -\end{questions} - -Lab Instructor Signature\underline{\hspace{7.5cm}} - -\end{document} diff --git a/handouts/Lab11-Structs.pdf b/handouts/Lab11-Structs.pdf deleted file mode 100644 index 0c978dc..0000000 Binary files a/handouts/Lab11-Structs.pdf and /dev/null differ diff --git a/handouts/Lab11-Structs.tex b/handouts/Lab11-Structs.tex deleted file mode 100755 index b5087ea..0000000 --- a/handouts/Lab11-Structs.tex +++ /dev/null @@ -1,318 +0,0 @@ -\documentclass[12pt]{scrartcl} - - -\setlength{\parindent}{0pt} -\setlength{\parskip}{.25cm} - -\usepackage{graphicx} - -\usepackage{xcolor} - -\definecolor{darkred}{rgb}{0.5,0,0} -\definecolor{darkgreen}{rgb}{0,0.5,0} -\usepackage{hyperref} -\hypersetup{ - letterpaper, - colorlinks, - linkcolor=red, - citecolor=darkgreen, - menucolor=darkred, - urlcolor=blue, - pdfpagemode=none, - pdftitle={Lab 11.0 - Encapsulation and Structures}, - pdfauthor={Christopher M. Bourke} - pdfkeywords={} -} - -\definecolor{MyDarkBlue}{rgb}{0,0.08,0.45} -\definecolor{MyDarkRed}{rgb}{0.45,0.08,0} -\definecolor{MyDarkGreen}{rgb}{0.08,0.45,0.08} - -\definecolor{mintedBackground}{rgb}{0.95,0.95,0.95} -\definecolor{mintedInlineBackground}{rgb}{.90,.90,1} - -%\usepackage{newfloat} -\usepackage[newfloat=true]{minted} -\setminted{mathescape, - linenos, - autogobble, - frame=none, - framesep=2mm, - framerule=0.4pt, - %label=foo, - xleftmargin=2em, - xrightmargin=0em, - startinline=true, %PHP only, allow it to omit the PHP Tags *** with this option, variables using dollar sign in comments are treated as latex math - numbersep=10pt, %gap between line numbers and start of line - style=default, %syntax highlighting style, default is "default" - %gallery: http://help.farbox.com/pygments.html - %list available: pygmentize -L styles - bgcolor=mintedBackground} %prevents breaking across pages - -\setmintedinline{bgcolor={mintedBackground}} -\setminted[text]{bgcolor={mintedBackground},linenos=false,autogobble,xleftmargin=1em} -%\setminted[php]{bgcolor=mintedBackgroundPHP} %startinline=True} -\SetupFloatingEnvironment{listing}{name=Code Sample} -\SetupFloatingEnvironment{listing}{listname=List of Code Samples} - - -\title{CSCE 155 - C} -\subtitle{Lab 11.0 - Encapsulation \& Structs} -\author{~} -\date{~} - -\begin{document} - -\maketitle - -\section*{Prior to Lab} - -Before attending this lab: -\begin{enumerate} - \item Read and familiarize yourself with this handout. - \item Read Chapters 10 and 23 of the \href{http://cse.unl.edu/~cbourke/ComputerScienceOne.pdf}{Computer Science I} textbook - \item Watch Videos 11.1 thru 11.3 of the \href{https://www.youtube.com/playlist?list=PL4IH6CVPpTZVkiEnCEOdGbYsFEdtKc5Bx}{Computer Science I} video series -\end{enumerate} - -\section*{Peer Programming Pair-Up} - -\textbf{For students in the online section:} you may complete -the lab on your own if you wish or you may team up with a partner -of your choosing, or, you may consult with a lab instructor to get -teamed up online (via Zoom). - -\textbf{For students in the face-to-face section:} your -lab instructor will team you up with a partner. - -To encourage collaboration and a team environment, labs are be -structured in a \emph{peer programming} setup. At the start of -each lab, you will be randomly paired up with another student -(conflicts such as absences will be dealt with by the lab instructor). -One of you will be designated the \emph{driver} and the other -the \emph{navigator}. - -The navigator will be responsible for reading the instructions and -telling the driver what to do next. The driver will be in charge of the -keyboard and workstation. Both driver and navigator are responsible -for suggesting fixes and solutions together. Neither the navigator -nor the driver is ``in charge.'' Beyond your immediate pairing, you -are encouraged to help and interact and with other pairs in the lab. - -Each week you should alternate: if you were a driver last week, -be a navigator next, etc. Resolve any issues (you were both drivers -last week) within your pair. Ask the lab instructor to resolve issues -only when you cannot come to a consensus. - -Because of the peer programming setup of labs, it is absolutely -essential that you complete any pre-lab activities and familiarize -yourself with the handouts prior to coming to lab. Failure to do -so will negatively impact your ability to collaborate and work with -others which may mean that you will not be able to complete the -lab. - - -\section{Lab Objectives \& Topics} -At the end of this lab you should be familiar with the following -\begin{itemize} - \item Be familiar with the concepts of encapsulation \& modularity - \item Understand how to design, declare, and use C structures - (both by reference and by value) - \item Have some exposure to advanced topics such as sockets, - the HTTP protocol, and XML processing -\end{itemize} - -\section{Background} - -An RSS feed (RDF Site Summary or ``Really Simple Syndication'') -is a format used to publish frequently updated works. RSS enabled -clients can subscribe to RSS feeds and update a user as to new or -relevant news items. RSS feeds are most commonly formatted using -XML (Extensible Markup Language) that use XML tags to indicate -what the data represents (the title of the article, a short description, -etc.). Clients ``read'' an RSS feed by making a connection to a server -using the HyperText Transfer Protocol (HTTP). - -For example, UNL has an RSS news feed available at \url{http://newsroom.unl.edu/releases/?format=xml} -which serves XML data that looks something like the following: - -\begin{minted}[breaklines]{xml} - - - UNL News Releases - http://newsroom.unl.edu/releases/ - News from the University of Nebraska-Lincoln - en-us - Copyright 2012 University of Nebraska-Lincoln - - UNL News Releases - http://www.unl.edu/favicon.ico - http://www.unl.edu/ - - - Guerrilla Girls on Tour perform 'Feminists are Funny' Monday at Sheldon - http://newsroom.unl.edu/releases/2012/03/09/Guerrilla - The Guerrilla Girls on Tour, an internationally acclaimed anonymous theater collective, will perform "Feminists are Funny" at the University of Nebraska-Lincoln's Sheldon Museum of Art, 12th and R streets, at 7 p.m. March 12. The 70-minute play is an... - - Fri, 09 Mar 2012 02:00:00 -0600 - - ... - - -\end{minted} - -\subsection*{Structures in C} - -An entity may be composed of several different pieces of data. -A person for example may have a first and last name (strings), -an age (integer), a birthdate (some date/time representation), -etc. Its much easier and more natural to group each of these -pieces of data into one entity. This is a concept known as -\emph{encapsulation}--a mechanism by which data can be -grouped together to define an entity. - -The C programming language provides a mechanism to achieve -encapsulation using structures. Structures are user defined types -that have one or more data fields--variables which have a type -and a name. To access the member fields of a structure you can -use the dot operator; example: \mintinline{c}{student.firstName}. -However, when you have a reference to a structure, you need to -use the arrow operator: \mintinline{c}{student->firstName}. - -\subsection*{RSS Client Background} - -You have been provided with an incomplete RSS client written in C. -The client works as follows: based on a URL (which consists of a -host and a resource on that host), it opens a socket connection and -sends a GET request to the server. The server responds with a -stream of data that the client reads into a buffer. This data stream -can, in general, be any type of data, but we're expecting an RSS -feed--a stream of plain text XML-formatted data conforming to the -RSS standard. Since the data is plain text, it is stored in a -character array which is then handed off to another function -to parse the XML document. This is done using a library (libxml2, -an XML parser and toolkit for Gnome). - -\section{Activities} - -Clone the project code for this lab from GitHub by using the following URL: -\url{https://github.com/cbourke/CSCE155-C-Lab11}. - -If you are using the CS50 IDE you may need to install the curl development -library before compiling this lab: - -\mintinline{text}{sudo apt-get install libcurl4-gnutls-dev} - -\subsection{A Student Structure} - -This activity will familiarize you with a completed program in which -a C structure has been declared to represent a student. Several -functions have been implemented to assist in the construction and -printing of this structure. In particular there are two ``factory'' -functions that can be used to help in the construction of an individual -structure. The factory function takes the appropriate parameters, -allocates memory to hold a new student and sets each field of the -student appropriately. In the case of strings, malloc is used to create -enough space and the string is then copied. The birthdate is handled -specially: it parses the date string and creates a \mintinline{c}{struct tm} -which is a \emph{time} structure defined by the time library -(\mintinline{text}{time.h}). Ultimately, a pointer to the new student -structure is returned. There is also a print function that takes a -student (by reference) and prints it out to the standard output. - - -\subsubsection*{Instructions} - -\begin{enumerate} - \item Examine the syntax and program structure and observe how - each factory function works as well as how they are used. - \item Change the values in the \mintinline{c}{main} function to your - name, NUID, and birth date. - \item Compile and run the program. Refer back to this program in - the next activity as needed. -\end{enumerate} - -\subsection{Completing the RSS Client} - -In this activity, you will complete the RSS Client that connects to a UNL -RSS feed, processes the XML data and outputs the results to the -standard output. Most of the client has been completed for you. -You just need to complete the design and implementation of a C -structure that models the essential parts of an RSS item. Your -structure will need to support an RSS item's title, link, description, -and publication date. - -To keep things simple, we recommend that you represent the date using -a string. If you would like to try using the \mintinline{c}{tm} structure -defined in the time library, you may find the following documentation -useful: \url{http://pubs.opengroup.org/onlinepubs/7908799/xsh/time.h.html} - -\subsubsection*{Instructions} - -\begin{enumerate} - \item We have provided 3 different RSS feeds to work with in the - program. You can switch between them using command line arguments. - \item Design and implement the RSS structure - \item Complete the other functions - \begin{itemize} - \item \mintinline{c}{createEmptyRss()} - this function should create an - ``empty'' RSS structure - \item \mintinline{c}{createRss()} - this function should construct an RSS - structure based on the input parameters. For the date, use a string - representation (RSS and Atom feeds can use a variety of formats and - there is no easy way to automatically parse them). - \item \mintinline{c}{printRss()} - this function should print the given RSS - to the standard output in a human readable format (the details are up to you). - \end{itemize} - \item You will need to use the makefile to compile your program as it - contains the flags necessary to import the proper XML libraries. - Recall that you can execute the makefile by typing the \mintinline{text}{make} - command. -\end{enumerate} - -\section{Handin/Grader Instructions} - -\begin{enumerate} - \item Hand in your completed files: - \begin{itemize} - \item \mintinline{text}{rss.h} - \item \mintinline{text}{rss.c} - \item \mintinline{text}{worksheet.md} - \end{itemize} - through the webhandin (\url{https://cse-apps.unl.edu/handin}) - using your cse login and password. - \item Even if you worked with a partner, you \emph{both} should - turn in all files. - \item Verify your program by grading yourself through the - webgrader (\url{https://cse.unl.edu/~cse155e/grade/}) using the - same credentials. - \item Recall that both expected output and your program's output - will be displayed. The formatting may differ slightly which is fine. - As long as your program successfully compiles, runs and outputs - the \emph{same values}, it is considered correct. -\end{enumerate} - - -\section{Advanced Activity (Optional)} - -\begin{enumerate} - \item You will notice that internally, we have provided support for both - RSS 2.0 feeds and Atom 1.0 feeds (Reddit uses Atom for example). - Examine the files where we have defined these feeds. Find an RSS or Atom - feed that is of interest to you and integrate it as an option for this program. - Be sure to change the main function so that it can be used. - - \item Improve the program further by modifying the \mintinline{c}{parseRSS_XML} - function. Currently, this function parses the XML but limits the number of - RSS structures to a maximum of 100. Write another function to count the - number of items in the XML and use it to instead dynamically allocate an - RSS array of a size exactly equal to the number of item elements in the XML file. -\end{enumerate} - -For additional Information: - \begin{itemize} - \item RSS: \url{http://en.wikipedia.org/wiki/RSS} - \item HTTP Protocol: \url{http://en.wikipedia.org/wiki/HTTP} - \item C Sockets: \url{http://www.linuxhowtos.org/C_C++/socket.htm} - \end{itemize} - -\end{document} diff --git a/readme.md b/readme.md index 6590910..a6d9760 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,254 @@ # Computer Science I ## Lab 11.0 - Encapsulation & Structures -This is a lab used in Computer Science I (CSCE 155E, CSCE 155H) in the [Department of Computer Science & Engineering](https://cse.unl.edu) at the [University of Nebraska-Lincoln](https://unl.edu). +This is a lab used in Computer Science I (CSCE 155E, CSCE 155H) in the +[Department of Computer Science & Engineering](https://cse.unl.edu) at the +[University of Nebraska-Lincoln](https://unl.edu). + +## 1. Overview + +### Prior to Lab + +Before attending this lab: + +1. Read and familiarize yourself with this handout. + +2. Read Chapters 10 and 23 of the [Computer Science + I](http://cse.unl.edu/~cbourke/ComputerScienceOne.pdf) textbook + +3. Watch Videos 11.1 thru 11.3 of the [Computer Science + I](https://www.youtube.com/playlist?list=PL4IH6CVPpTZVkiEnCEOdGbYsFEdtKc5Bx) + video series + +### Peer Programming Pair-Up + +**For students in the online section:** you may complete the lab on your +own if you wish or you may team up with a partner of your choosing. You +may consult with a lab instructor to get teamed up online (via Zoom). + +**For students in the face-to-face section:** your lab instructor will +team you up with a partner. + +To encourage collaboration and a team environment, labs are be +structured in a *peer programming* setup. At the start of each lab, you +will be randomly paired up with another student (conflicts such as +absences will be dealt with by the lab instructor). One of you will be +designated the *driver* and the other the *navigator*. + +The navigator will be responsible for reading the instructions and +telling the driver what to do next. The driver will be in charge of the +keyboard and workstation. Both driver and navigator are responsible for +suggesting fixes and solutions together. Neither the navigator nor the +driver is "in charge." Beyond your immediate pairing, you are encouraged +to help and interact and with other pairs in the lab. + +Each week you should alternate: if you were a driver last week, be a +navigator next, etc. Resolve any issues (you were both drivers last +week) within your pair. Ask the lab instructor to resolve issues only +when you cannot come to a consensus. + +Because of the peer programming setup of labs, it is absolutely +essential that you complete any pre-lab activities and familiarize +yourself with the handouts prior to coming to lab. Failure to do so will +negatively impact your ability to collaborate and work with others which +may mean that you will not be able to complete the lab. + +### Lab Objectives & Topics +======================= + +At the end of this lab you should be familiar with the following + +- Be familiar with the concepts of encapsulation & modularity + +- Understand how to design, declare, and use C structures (both by + reference and by value) + +- Have some exposure to advanced topics such as sockets, the HTTP + protocol, and XML processing + +## 2. Background + +### 2.1 RSS Feeds + +An RSS feed (RDF Site Summary or "Really Simple Syndication") is a +format used to publish frequently updated works. RSS enabled clients can +subscribe to RSS feeds and update a user as to new or relevant news +items. RSS feeds are most commonly formatted using XML (Extensible +Markup Language) that use XML tags to indicate what the data represents +(the title of the article, a short description, etc.). Clients "read" an +RSS feed by making a connection to a server using the HyperText Transfer +Protocol (HTTP). + +For example, UNL has an RSS news feed available at + which serves XML data +that looks something like the following: + +```xml + + + UNL News Releases + http://newsroom.unl.edu/releases/ + News from the University of Nebraska-Lincoln + en-us + Copyright 2012 University of Nebraska-Lincoln + + UNL News Releases + http://www.unl.edu/favicon.ico + http://www.unl.edu/ + + + Guerrilla Girls on Tour perform 'Feminists are Funny' Monday at Sheldon + http://newsroom.unl.edu/releases/2012/03/09/Guerrilla + The Guerrilla Girls on Tour, an internationally acclaimed anonymous theater collective, will perform "Feminists are Funny" at the University of Nebraska-Lincoln's Sheldon Museum of Art, 12th and R streets, at 7 p.m. March 12. The 70-minute play is an... + + Fri, 09 Mar 2012 02:00:00 -0600 + + ... + + +``` + +### 2.2 Structures in C + +An entity may be composed of several different pieces of data. A person +for example may have a first and last name (strings), an age (integer), +a birthdate (some date/time representation), etc. Its much easier and +more natural to group each of these pieces of data into one entity. This +is a concept known as *encapsulation*--a mechanism by which data can be +grouped together to define an entity. + +The C programming language provides a mechanism to achieve encapsulation +using structures. Structures are user defined types that have one or +more data fields–variables which have a type and a name. To access the +member fields of a structure you can use the dot operator; example: . +`student.firstName`. However, when you have a reference (pointer) to a +structure, you need to use the arrow operator: `student->firstName`. + +### 2.3 RSS Client Background + +You have been provided with an incomplete RSS client written in C. The +client uses the cURL library (Client URL) library to make an HTTP +(or a secure HTTPS) connection using a URL (a web address) to an RSS +server. The server responds with a stream of data that +the client reads into a buffer. This data stream can, in general, be any +type of data, but we're expecting an RSS feed--a stream of plain text +XML-formatted data conforming to the RSS standard. Since the data is +plain text, it is stored in a character array which is then handed off +to another function to parse the XML document. This is done using an XML +library (libxml2, an XML parser and toolkit for Gnome). + +## 3. Activities + +### 3.1 Getting Started + +Clone the project code for this lab from GitHub by using the following +URL: . + +If you are using the CS50 IDE you may need to install the curl +development library before compiling this lab: + +`sudo apt-get install libcurl4-gnutls-dev` + +### 3.2 `Student` Structure Demo + +To demonstrate how to define and use a structure, we have provided a +completed program (see the files in the `studentDemo` directory) +with a full structure definition to model a student. +Several functions have been implemented to assist in the construction +and printing of this structure. In particular there are two "factory" +functions that can be used to help in the construction of an individual +structure. The factory function takes the appropriate parameters, allocates +memory for a new `Student` instance and sets each field of the structure +appropriately. In the case of strings, `malloc` is used to create enough +space and the string is then copied. The `birthDate` is handled specially: +it parses the date string and creates a `struct tm` which is a *time* structure +defined by the time library (`time.h`). Finally, a pointer to the new +`Student` structure is returned. There is also a print function that takes +a student (by reference) and prints it out to the standard output. + +#### Instructions + +1. Examine the syntax and program structure and observe how each + factory function works as well as how they are used. + +2. Change the values in the function to your name, NUID, and birth + date. + +3. Compile and run the program using the following commands. + ```text + gcc -c -std=gnu89 student.c + gcc student.o studentDemo.c + ``` + Run your program and observe the results. Refer back to this + program in the next activity as needed. + +### 3.3 Completing the RSS Client + +In this activity, you will complete the RSS Client that connects to a +UNL RSS feed, processes the XML data and outputs the results to the +standard output. Most of the client has been completed for you. You just +need to complete the design and implementation of a C structure that +models the essential parts of an RSS "item" (usually an individual +news story). Your structure will need to support an RSS item's title, +link, description, and publication date. + +To keep things simple, we recommend that you represent the date using a +string. If you would like to try using the structure defined in the time +library, you may find the following documentation useful: + + + +#### Instructions + +1. Go to the `rss` directory. We have provided a collection of source + files to do most of the work for you. To compile it, we have provided + a `makefile`. Simply type `make` and it produces an executable called + `runRss`. + +2. Examine the `main` function in `runRss.c` and observe how to use + the program to connect to three different RSS feeds using + command line arguments. + +3. Design and implement the RSS structure in the `rss.h` header file + +4. Complete all the functions as specified in their documentation. + + +## 4. Handin/Grader Instructions + +1. Hand in your completed files: + + - `rss.h` + - `rss.c` + + through the webhandin () using your + cse login and password. + +2. Even if you worked with a partner, you *both* should turn in all + files. + +3. Verify your program by grading yourself through the webgrader + () using the same credentials. + +4. Recall that both expected output and your program's output will be + displayed. The formatting may differ slightly which is fine. As long + as your program successfully compiles, runs and outputs the *same + values*, it is considered correct. + +## Advanced Activity (Optional) + +1. You will notice that internally, we have provided support for both + RSS 2.0 feeds and Atom 1.0 feeds (Reddit uses Atom for example). + Examine the files where we have defined these feeds. Find an RSS or + Atom feed that is of interest to you and integrate it as an option + for this program. Be sure to update the `main` function so that it can + be used. + +2. Improve the program further by modifying the `parseRssXml` function. Currently, + this function parses the XML but limits the number of RSS structures + to a maximum of 100. Write another function to count the number of + items in the XML and use it to instead dynamically allocate an RSS + array of a size exactly equal to the number of item elements in the + XML file. + + diff --git a/curlTest.c b/rss/curlTest.c similarity index 100% rename from curlTest.c rename to rss/curlTest.c diff --git a/curl_utils.c b/rss/curl_utils.c similarity index 91% rename from curl_utils.c rename to rss/curl_utils.c index 9c4269e..c5e1ba0 100644 --- a/curl_utils.c +++ b/rss/curl_utils.c @@ -44,7 +44,10 @@ char *getContent(const char *url) { curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); res = curl_easy_perform(curl); - + if(res != CURLE_OK) { + fprintf(stderr, "cURL encountered an error: %s\n", curl_easy_strerror(res)); + } + result = (char *)malloc(sizeof(char) * (strlen(s.ptr) + 1)); strcpy(result, s.ptr); free(s.ptr); diff --git a/curl_utils.h b/rss/curl_utils.h similarity index 100% rename from curl_utils.h rename to rss/curl_utils.h diff --git a/makefile b/rss/makefile similarity index 96% rename from makefile rename to rss/makefile index d11d8ff..9478c8a 100644 --- a/makefile +++ b/rss/makefile @@ -3,7 +3,7 @@ # # compile with gcc -CC = gcc -Wall +CC = gcc -std=gnu99 -Wall # XML libraries XML_INCLUDE = -I/usr/include/libxml2 diff --git a/rss.c b/rss/rss.c similarity index 61% rename from rss.c rename to rss/rss.c index f32e94a..a5178d1 100644 --- a/rss.c +++ b/rss/rss.c @@ -12,5 +12,9 @@ Rss * createEmptyRss() { Rss * createRss(const char * title, const char * link, const char * date, const char * description) { } -void printRss(Rss * item) { +void initRss(Rss *feed, const char* title, const char* link, const char* date, + const char* description); + + +void printRss(const Rss * item) { } diff --git a/rss.h b/rss/rss.h similarity index 64% rename from rss.h rename to rss/rss.h index 1b0fffb..f5c03fb 100644 --- a/rss.h +++ b/rss/rss.h @@ -16,8 +16,15 @@ Rss* createEmptyRss(); Rss* createRss(const char* title, const char* link, const char* date, const char* description); +/** + * An initialization function to initialize an RSS feed with the + * given values. + */ +void initRss(Rss *feed, const char* title, const char* link, const char* date, + const char* description); + /** * A function that prints the given Rss structure * to the standard output. */ -void printRss(Rss* item); +void printRss(const Rss* item); diff --git a/rss_utils.c b/rss/rss_utils.c similarity index 100% rename from rss_utils.c rename to rss/rss_utils.c diff --git a/rss_utils.h b/rss/rss_utils.h similarity index 59% rename from rss_utils.h rename to rss/rss_utils.h index f684973..77522b3 100644 --- a/rss_utils.h +++ b/rss/rss_utils.h @@ -17,22 +17,22 @@ typedef struct { } RssService; static const RssService cseBitsAndBytes = { - "CSE Bits and Bytes", "https://newsroom.unl.edu/announce/cse/?format=rss", + "CSE Bits and Bytes", + "https://newsroom.unl.edu/announce/cse/?format=rss", RSS2}; static const RssService huskerNews = { "Husker Sports News", - "https://huskers.com/rss.aspx", RSS2}; + "https://huskers.com/rss.aspx", + RSS2}; /** - * An RSS feed of Reddit's front page. Be aware: reddit - * forces an SSL connection, so we've been forced to use a - * non-SSL proxy here. Depending on the fickleness of your - * instructor, this may or may not be working. + * An RSS feed of Reddit's front page. */ static const RssService reddit = { - "Reddit", "https://www.reddit.com/.rss", - ATOM1}; + "Reddit", + "https://www.reddit.com/.rss", + ATOM1}; /** * A utility function to parse an XML feed from an RSS feed diff --git a/runRss.c b/rss/runRss.c similarity index 86% rename from runRss.c rename to rss/runRss.c index 37219f1..0565087 100644 --- a/runRss.c +++ b/rss/runRss.c @@ -9,6 +9,10 @@ #include "rss_utils.h" #include "rss.h" +/** + * Main driver program for the RSS feed demo. You can provide + * command line arguments 1 - 3 to connect to different feeds. + */ int main(int argc, char **argv) { // default: UNL News RssService s = cseBitsAndBytes; diff --git a/studentDemo.c b/studentDemo/student.c similarity index 61% rename from studentDemo.c rename to studentDemo/student.c index 594d991..2b4090e 100644 --- a/studentDemo.c +++ b/studentDemo/student.c @@ -1,42 +1,49 @@ #include #include -#include #include +#include + +#include "student.h" + +Student *createEmptyStudent() { + return createStudent("", "", 0, ""); +} -/** - * A structure modeling a UNL student with - * first name, last name, nuid and a birth date - * (as a tm, "time" structure) - */ -typedef struct { - char *firstName; - char *lastName; - int nuid; - struct tm birthDate; -} Student; - -/** - * Creates an "empty" Student struct with default values - */ -Student *createEmptyStudent(); - -/** - * Creates a Student struct with the given values - */ Student *createStudent(const char *firstName, const char *lastName, int nuid, - const char *birthDate_str); + const char *birthDate_str) { + Student *student = (Student *)malloc(sizeof(Student) * 1); + + student->firstName = (char *)malloc(sizeof(char) * (strlen(firstName) + 1)); + strcpy(student->firstName, firstName); + + student->lastName = (char *)malloc(sizeof(char) * (strlen(lastName) + 1)); + strcpy(student->lastName, lastName); + + student->nuid = nuid; -/** - * Prints the given Student struct to the standard output - */ -void printStudent(Student *student); + strptime(birthDate_str, "%m/%d/%Y", &(student->birthDate)); -int main(int argc, char **argv) { - Student *me = createStudent("Joe", "Smith", 140602, "07/30/1980"); - printStudent(me); + return student; } -char *studentToString(Student *student) { +void initStudent(Student *student, + const char *firstName, const char *lastName, int nuid, + const char *birthDate_str) { + student->firstName = (char *)malloc(sizeof(char) * (strlen(firstName) + 1)); + strcpy(student->firstName, firstName); + + student->lastName = (char *)malloc(sizeof(char) * (strlen(lastName) + 1)); + strcpy(student->lastName, lastName); + + student->nuid = nuid; + + strptime(birthDate_str, "%m/%d/%Y", &(student->birthDate)); + + return; +} + + +char *studentToString(const Student *student) { if (student == NULL) { char *result = (char *)malloc(sizeof(char) * 7); strcpy(result, "(null)"); @@ -60,28 +67,10 @@ char *studentToString(Student *student) { return str; } -void printStudent(Student *student) { +void printStudent(const Student *student) { char *str = studentToString(student); printf("%s\n", str); free(str); return; } -Student *createEmptyStudent() { return createStudent("", "", 0, ""); } - -Student *createStudent(const char *firstName, const char *lastName, int nuid, - const char *birthDate_str) { - Student *student = (Student *)malloc(sizeof(Student) * 1); - - student->firstName = (char *)malloc(sizeof(char) * (strlen(firstName) + 1)); - strcpy(student->firstName, firstName); - - student->lastName = (char *)malloc(sizeof(char) * (strlen(lastName) + 1)); - strcpy(student->lastName, lastName); - - student->nuid = nuid; - - strptime(birthDate_str, "%m/%d/%Y", &(student->birthDate)); - - return student; -} diff --git a/studentDemo/student.h b/studentDemo/student.h new file mode 100644 index 0000000..2e9b862 --- /dev/null +++ b/studentDemo/student.h @@ -0,0 +1,44 @@ +#include + +/** + * A structure modeling a UNL student with + * first name, last name, nuid and a birth date + * (as a tm, "time" structure) + */ +typedef struct { + char *firstName; + char *lastName; + int nuid; + struct tm birthDate; +} Student; + +/** + * Creates an "empty" Student struct with default values + */ +Student *createEmptyStudent(); + +/** + * Creates a Student struct with the given values + */ +Student *createStudent(const char *firstName, const char *lastName, int nuid, + const char *birthDate_str); + +/** + * Initializes the given Student sturcture with the + * given values + */ +void initStudent(Student *student, + const char *firstName, const char *lastName, int nuid, + const char *birthDate_str); + +/** + * Prints the given Student struct to the standard output + */ +void printStudent(const Student *student); + +/** + * Returns a string representation of the given student + */ +char *studentToString(const Student *student); + + diff --git a/studentDemo/studentDemo.c b/studentDemo/studentDemo.c new file mode 100644 index 0000000..9172a66 --- /dev/null +++ b/studentDemo/studentDemo.c @@ -0,0 +1,12 @@ +#include + +#include "student.h" + +/** + * Student structure demonstration program + */ +int main(int argc, char **argv) { + Student *me = createStudent("Joe", "Smith", 140602, "07/30/1980"); + printStudent(me); +} + diff --git a/worksheet.md b/worksheet.md deleted file mode 100644 index 84a4e80..0000000 --- a/worksheet.md +++ /dev/null @@ -1,28 +0,0 @@ - -# CSCE 155E -## Lab 11.0 Worksheet - -Name(s) and Login(s): - - - -1. Which RSS feed did you choose and what is the most recent - story published through it? - - - -2. How many stories were available on the RSS feed when you - executed your program? - - - -3. Closely examine the description and titles of each of the - RSS items. Do you notice any weird characters or odd formatting? - Can you explain them? - - - - - - -