{"id":6501,"date":"2021-11-25T22:26:11","date_gmt":"2021-11-25T20:26:11","guid":{"rendered":"https:\/\/blue.pri.ee\/ttu\/?p=6501"},"modified":"2025-11-27T12:18:43","modified_gmt":"2025-11-27T10:18:43","slug":"pr1en13-strings","status":"publish","type":"post","link":"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/","title":{"rendered":"PR1EN13: Strings"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#Lab_materials\" >Lab materials<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#Lab_tasks\" >Lab tasks<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#Task_1_W13-1_Introducing_the_stringh_library\" >Task 1 [W13-1]: Introducing the string.h library<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#Requirements\" >Requirements<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#Helper_function_for_debugging\" >Helper function for debugging<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#Step-by-step_guide\" >Step-by-step guide<\/a><ul class='ez-toc-list-level-6' ><li class='ez-toc-heading-level-6'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#1_step_getting_user_input\" >1. step: getting user input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-6'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#2_step_read_a_sentence_and_print_its_length\" >2. step: read a sentence and print its length<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-6'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#3_step_search_phrase\" >3. step: search phrase<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-6'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#4_step_password_prompt\" >4. step: password prompt<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-6'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#5_step_composing_a_sentence\" >5. step: composing a sentence<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#Example\" >Example<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#Extra_task_W13-3_Alternative_count\" >Extra task [W13-3]: Alternative count<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#Task_2_W13-2_Generating_e-mail_addresses_from_CSV\" >Task 2 [W13-2]: Generating e-mail addresses from CSV<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#CSV_format\" >CSV format<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#Requirements-2\" >Requirements<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#Example-2\" >Example<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#Hints\" >Hints<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#Extra_task_1_W13-4_Short_names\" >Extra task 1 [W13-4]: Short names<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#Extra_task_2_W13-5_Unique_e-mail_addresses\" >Extra task 2 [W13-5: Unique e-mail addresses<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#After_this_lesson_you_should\" >After this lesson, you should<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/#Additional_content\" >Additional content<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Lab_materials\"><\/span><strong>Lab materials<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Slides: <a href=\"https:\/\/blue.pri.ee\/ttu\/files\/iax0583\/slaidid-en\/13_strings.pdf\"><strong>Strings<\/strong><\/a><\/li>\n<li>Sample:\u00a0<strong><a href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/samples\/characters-c\/\">Some simpler character assignments<\/a><\/strong><\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Lab_tasks\"><\/span>Lab tasks<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>In this task you have two tasks. The first task focuses on using string.h library and reading input from the user. The second task looks at manipulating strings manually and introduces you to CSV (comma separated value) format.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Task_1_W13-1_Introducing_the_stringh_library\"><\/span>Task 1 [W13-1]: Introducing the string.h library<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>In this task, there are two main goals. First, we&#8217;ll look at reading input from the user safely. The second goal is to get acquainted with some of the standard functions in the string.h library. This will be done in a step-by-step manner.<\/p>\n<h5><span class=\"ez-toc-section\" id=\"Requirements\"><\/span>Requirements<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<ul>\n<li><strong>Follow the step-by-step guide to solve the task!<\/strong><\/li>\n<li>The program must ask for a predefined password. It must not allowed to proceed before a correct password is entered.<\/li>\n<li>Ask user for a sentence. The program must show how many characters there were in the given sentence (including spaces, punctuation).<\/li>\n<li>The user is asked for a search phrase. Check if the search phrase was present in the previously entered sentence (yes\/no answer).<\/li>\n<li>User is asked for two words, which are used to compose a sentence\n<ul>\n<li>You can choose the types of words yourself (e.g. verbs, nouns, names of items, names of people etc)<\/li>\n<li>You can also choose the sentence you wish to compose<\/li>\n<li>Compose the given words with others to compose a simple sentence consisting of at least 4 words.<\/li>\n<li>One of the words given by the user must be the first word in this sentence.<\/li>\n<li>The composed sentence must be written in a completely new (empty) variable, which must fit the composed sentence even in the worst case scenario (e.g. maximum possible length for both user-entered words).<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h5><span class=\"ez-toc-section\" id=\"Helper_function_for_debugging\"><\/span>Helper function for debugging<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>To better understand the contents of a string (i.e. the character array), the following helper function is provided for you. It prints the string out first, followed by printing each individual character (one per line). It will print the index, ASCII code and the character it represents. This should help you identify any stray or unwanted characters. Note that you can&#8217;t identify uninitialized array slots with this function!<\/p>\n<pre class=\"toolbar:1 lang:default decode:true\">void DebugString(char str[])\r\n{\r\n    int i = 0;\r\n    printf(\"String is: '%s'\\n\", str);\r\n    while (str[i] != '\\0')\r\n    {\r\n        printf(\"str[%d] = %3hhu %c\\n\", i, str[i], str[i]);\r\n        i++;\r\n    }\r\n    printf(\"\\n\");\r\n}<\/pre>\n<h5><span class=\"ez-toc-section\" id=\"Step-by-step_guide\"><\/span>Step-by-step guide<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<h6><span class=\"ez-toc-section\" id=\"1_step_getting_user_input\"><\/span>1. step: getting user input<span class=\"ez-toc-section-end\"><\/span><\/h6>\n<p>The first step will be done in class together, but you can also follow this guide instead. In this step we will create two functions necessary for our program.<\/p>\n<p>In the first function, the focus is on reading input safely. The solution should also be able to read input that spans multiple words, i.e. includes spaces. There are multiple solutions to solve this, but we&#8217;ll use <span class=\"lang:c highlight:0 decode:true crayon-inline \">fgets()<\/span>\u00a0 function within this guide.<\/p>\n<p>The function\u00a0 <span class=\"lang:default highlight:0 decode:true crayon-inline\">fgets()<\/span>\u00a0 is meant to be used for reading files. However everything is a file, including the data stream coming from the keyboard. To take advantage of this, the data will be read from a file stream named\u00a0 <span class=\"lang:default highlight:0 decode:true crayon-inline\">stdin<\/span> , which you are familiar with as the standard input stream. Secondly, the function requires specifying the maximum length for the input &#8211; this is for safety, so it wouldn&#8217;t be susceptible to buffer overflow attacks. The third gotcha is that when we press the enter key on the keyboard, it signals a newline <span class=\"lang:default highlight:0 decode:true crayon-inline\">\\n<\/span> , which is also stored into the array. This needs to be cleaned up as well.<\/p>\n<p>To make these functions more convenient to use,\u00a0 we&#8217;ll create wrappers around those functions. The goal is to provide extra features, convenience or safety not present in the language itself. The wrapper for reading a string needs two inputs &#8211; the character array (string) to store the input and the maximum length of that string. The downside of this is of course making the program slower.<\/p>\n<p>There are three blanks left in the provided solution for you to fill in. Hint: if the read string is 10 characters, then at the index 8 is the last important character that the user entered. It is followed by the unwanted newline character, that needs to be removed by replacing it with the string terminator. You can use the helper function for better understanding the indexes and the position you need to make the correction at.<\/p>\n<p>In order for it to compile, the two lines handling the newline correction are commented out. Once you have replaced the question marks, comment them back in for it to work correctly.<\/p>\n<p>Note that it also contains a new type <span class=\"lang:c highlight:0 decode:true crayon-inline \">size_t<\/span>\u00a0. It&#8217;s a data type that is most commonly used for storing any kind of lengths, indexing arrays and counting. It&#8217;s an unsigned integer type.<\/p>\n<pre class=\"toolbar:2 lang:default decode:true\">void GetString(char str[], int max)\r\n{\r\n    \/\/ Read the string from keyboard\r\n    fgets(str, max, stdin);\r\n\r\n    \/\/ TODO: Find the length of the actual string we just read\r\n    \/\/ size_t len = ???;\r\n    \r\n    \/\/ TODO: Write the string terminator in place of the newline to fix the string\r\n    \/\/ str[ ??? ] = ???;\r\n}<\/pre>\n<p>Once the reading is completed, let&#8217;s write another wrapper, this time for our\u00a0 <span class=\"lang:default highlight:0 decode:true crayon-inline \">GetString()<\/span>\u00a0 function. This provides us with an option to read strings either with or without providing a prompt. There are other ways to do this without separate functions, but they are considered too complex for this course.<\/p>\n<pre class=\"toolbar:2 lang:default decode:true\">void PromptString(char str[], int max, char prompt[])\r\n{\r\n    printf(\"%s: \", prompt);\r\n    GetString(str, max);\r\n}<\/pre>\n<p>Now let&#8217;s try to get some input. In the example I have a character array <span class=\"lang:default highlight:0 decode:true crayon-inline \">sentence[]<\/span>\u00a0 , which has a length of\u00a0 <span class=\"lang:default highlight:0 decode:true crayon-inline\">MAX_STR<\/span> , defined a macro. The function call will look like this:<\/p>\n<pre class=\"toolbar:2 lang:default decode:true\">PromptString(sentence, STR_MAX, \"Please enter a sentence\");<\/pre>\n<h6><span class=\"ez-toc-section\" id=\"2_step_read_a_sentence_and_print_its_length\"><\/span>2. step: read a sentence and print its length<span class=\"ez-toc-section-end\"><\/span><\/h6>\n<p>Read a sentence from the user. Find and print the length of the sentence the user entered.<\/p>\n<h6><span class=\"ez-toc-section\" id=\"3_step_search_phrase\"><\/span>3. step: search phrase<span class=\"ez-toc-section-end\"><\/span><\/h6>\n<p>Add a new function, where you will ask the user to input a search phrase. The function should then print whether the phrase existed in the previously entered sentence or not.<\/p>\n<p>A yes\/no answer is enough. To achieve this, you can just check the return value of <span class=\"lang:c highlight:0 decode:true crayon-inline \">strstr()<\/span>\u00a0.<\/p>\n<p>Note, that the following example uses <span class=\"lang:c highlight:0 decode:true crayon-inline \">NULL<\/span> , which refers to a memory address or an object, that doesn&#8217;t exists.\u00a0 We call this the NULL-pointer. It is needed because the function <span class=\"lang:c highlight:0 decode:true crayon-inline \">strstr()<\/span>\u00a0 doesn&#8217;t just return a yes\/no answer, but instead gives you the location (memory address) where the search phrase is located at. It will be <span class=\"lang:c highlight:0 decode:true crayon-inline \">NULL<\/span>\u00a0, if it can&#8217;t find that location, i.e. the search phrase is not in the sentence.<\/p>\n<pre class=\"lang:default decode:true\">if (strstr() != NULL)\r\n{\r\n   \r\n}\r\nelse\r\n{\r\n    \r\n}<\/pre>\n<h6><span class=\"ez-toc-section\" id=\"4_step_password_prompt\"><\/span>4. step: password prompt<span class=\"ez-toc-section-end\"><\/span><\/h6>\n<p>Add a function to the program that will ask the user for their password. It could look something like this:<\/p>\n<pre class=\"toolbar:2 lang:default decode:true \">void PromptPassword(char correctPassword[])\r\n{\r\n    char userEnteredPassword[STR_MAX];\r\n    \r\n    \/\/ Write your loop for password prompt here\r\n}<\/pre>\n<p>The prompt must be inside of a loop in such a way that the user wouldn&#8217;t be able to proceed to use your program before they&#8217;ve entered a correct password. The password prompt must be case sensitive. If you wish, you can add hints on incorrect input or limit the amount of tries the user has.<\/p>\n<h6><span class=\"ez-toc-section\" id=\"5_step_composing_a_sentence\"><\/span>5. step: composing a sentence<span class=\"ez-toc-section-end\"><\/span><\/h6>\n<p>Add a function to your program that will compose a simple sentence of at least 4 words. Since we don&#8217;t have any good inputs or outputs for the function, we can create it as follows (typically avoid void-void functions!):<\/p>\n<pre class=\"toolbar:2 lang:default decode:true \">void FormulateSentence(void)\r\n{\r\n    \/\/ String where the final sentence will be held\r\n    char sentence[ ??? ];\r\n   \r\n    \/\/ Strings for the two user-entered words\r\n    \r\n\r\n    \/\/ Prompt the user for the two words\r\n\r\n\r\n    \/\/ Formulating the final sentence\r\n\r\n\r\n    \/\/ Print the final formulated sentence\r\n    printf(\"Result: %s\\n\", sentence);\r\n}<\/pre>\n<p><strong>Think!<\/strong> How long should the variable <span class=\"lang:default highlight:0 decode:true crayon-inline \">sentence<\/span>\u00a0 be in the worst case scenario, so that it would be able to hold both user entered words, as well as all the characters you are using to formulate the sentence? The size can be approximated, but must be sufficient!<\/p>\n<p>Now think of a sentence you wish to create. The sentence will have two gaps that the user will have to fill. You can choose which type of words go in there (names of objects, people, verbs, adjectives, &#8230;). One of the words that the user enters must be the at the start of the sentence. The location of the second word is up to you. E.g.\u00a0 <span class=\"lang:default highlight:0 decode:true crayon-inline\">&lt;word1&gt; is a &lt;word2&gt; name!<\/span> .<\/p>\n<p>Once you have asked the user for input and read the words, you must compose the sentence. The sentence must be written into a new, unused (empty) character array. You must account for the worst case scenario for fitting the sentence (when the user decides to enter the maximum possible length words for booth inputs).<\/p>\n<h5><span class=\"ez-toc-section\" id=\"Example\"><\/span>Example<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<pre class=\"theme:cisco-router toolbar:1 nums:false lang:default decode:true\" title=\"string.h\">Please enter a password: password\r\nInvalid password! Try again!\r\n\r\nPlease enter a password: again\r\nInvalid password! Try again!\r\n\r\nPlease enter a password: hunter2\r\nPassword accepted. Welcome AzureDiamond!\r\n\r\nEnter a sentence: I do wish we could chat longer, but I'm having an old friend for dinner.\r\nThe length of the entered sentence is 72\r\n\r\nPlease enter a search phrase: old friend\r\nYour search phrase \"old friend\" exists in the originally entered sentence\r\n\r\nEnter a name: Pauline\r\nEnter an adjective: awesome\r\n\r\nResult: Pauline is an awesome person!<\/pre>\n<h5><span class=\"ez-toc-section\" id=\"Extra_task_W13-3_Alternative_count\"><\/span>Extra task [W13-3]: Alternative count<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>Create a new function to do a manual count and add statistics<\/p>\n<ul>\n<li>Count and show how many alphabetical characters [a-zA-Z] there were. Do not count punctuation, spaces etc.<\/li>\n<li>Calculate and print the percentage of non-alphabetical characters in the sentence.<\/li>\n<li>Show the percentage with one place after the comma.<\/li>\n<\/ul>\n<p><strong>Example<\/strong><\/p>\n<pre class=\"theme:cisco-router toolbar:1 nums:false lang:default decode:true\" title=\"string_adv\">Sentence entered: Hi, Bob!\r\nSentence length: 8\r\nAlphabetical characters: 5\r\nPercentage of other characters: 37,5%<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"Task_2_W13-2_Generating_e-mail_addresses_from_CSV\"><\/span>Task 2 [W13-2]: Generating e-mail addresses from CSV<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>The goal of this task is to introduce you to CSV (comma separated value) format. You will be also be practicing manipulating characters individually.<\/p>\n<p>Download the starter code: <strong><a href=\"https:\/\/blue.pri.ee\/ttu\/files\/iax0583\/aluskoodid\/13_2_csv_starter.c\">13_2_csv_starter.c<\/a><\/strong><\/p>\n<h5><span class=\"ez-toc-section\" id=\"CSV_format\"><\/span>CSV format<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>CSV stands for comma separated value. CSV files are used for storing structured data. Every data field in a CSV file, as the name suggest, is separated by a comma. It&#8217;s one of the most widely used formats for storing and backing up data next to database systems themselves. The primary benefit of CSV is in its simplicity, making it supported by almost all applications that process any kind of data.<\/p>\n<p>In the most simple case, all data fields are separated by comas:<\/p>\n<pre class=\"toolbar:2 lang:default highlight:0 decode:true\">Mari,Maasikas,112222IACB,49001013333\r\nToomas,Toomingas,111111MVEB,39002204444<\/pre>\n<p>We are using the same complexity level for this lab task. To see how more complicated data is stored when you also need to store commas and quotes within the data fields, as well as add column headers, check here: <strong><a href=\"https:\/\/en.wikipedia.org\/wiki\/Comma-separated_values#Basic_rules\">https:\/\/en.wikipedia.org\/wiki\/Comma-separated_values#Basic_rules<\/a>.\u00a0<\/strong><\/p>\n<h5><span class=\"ez-toc-section\" id=\"Requirements-2\"><\/span>Requirements<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<ul>\n<li>The task must be built on the starter code.<\/li>\n<li>The program must create an e-mail address for all people listed in the CSV\n<ul>\n<li>The name part of the e-mail address must be composed of first 3 characters from the first name, followed by the first 3 characters of the last name.<\/li>\n<li>The name part is followed by a domain of your choosing<\/li>\n<li>You can only have lower case characters in the e-mail address<\/li>\n<li>The e-mail address must be stored in a new character array that you create. Print it to the screen from that array. You are not allowed to print the characters on the fly while processing the entry.<\/li>\n<\/ul>\n<\/li>\n<li>The program must print:\n<ul>\n<li>The full name of the person. First and last name must be separated by a space.<\/li>\n<li>Generated e-mail address<\/li>\n<\/ul>\n<\/li>\n<li>You are not allowed to change the code present in the starter code without a confirmation from us. The starting point of the code you write is in the function\u00a0 <span class=\"lang:default highlight:0 decode:true crayon-inline\">ProcessPerson()<\/span>\u00a0 . You are free (and recommended) to add more functions to the code.<\/li>\n<\/ul>\n<h5><span class=\"ez-toc-section\" id=\"Example-2\"><\/span>Example<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<pre class=\"theme:cisco-router toolbar:1 nums:false lang:default highlight:0 decode:true\" title=\"CSV\">Number of CSV lines: 3\r\n\r\nProcessing line: 'Maria,Kask'\r\nName: Maria Kask\r\nE-mail: markas@ttu.ee\r\n\r\nProcessing line: 'Johanna-Maria,Kask'\r\nName: Johanna-Maria Kask\r\nE-mail: johkas@ttu.ee\r\n\r\nProcessing line: 'Kalev Kristjan,Kuusk'\r\nName: Kalev Kristjan Kuusk\r\nE-mail: kalkuu@ttu.ee<\/pre>\n<h5><span class=\"ez-toc-section\" id=\"Hints\"><\/span>Hints<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<ul>\n<li>By knowing the location of the comma, you will also be able to calculate the position of the first character from the last name<\/li>\n<li>Lower and upper case ASCII characters differ from each other by a single bit, which is valued at 32 (e.g. A is 65, a is 97)<\/li>\n<li>All operations in this task besides adding the domain address in the end are easiest done character at a time. Library functions from <span class=\"lang:default highlight:0 decode:true crayon-inline \">string.h<\/span>\u00a0 can be used, but they might be unnecessarily complex for now.<\/li>\n<li>The most common mistake in this task is forgetting to add a string terminator to the end after copying over the name part of the address!<\/li>\n<\/ul>\n<h5><span class=\"ez-toc-section\" id=\"Extra_task_1_W13-4_Short_names\"><\/span>Extra task 1 [W13-4]: Short names<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>Change the way you are generating the e-mail addresses to accommodate people with shorter first or last names.<\/p>\n<p>Example: Ly Kask -&gt; lykask@ttu.ee<\/p>\n<h5><span class=\"ez-toc-section\" id=\"Extra_task_2_W13-5_Unique_e-mail_addresses\"><\/span>Extra task 2 [W13-5: Unique e-mail addresses<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>Change the way you are generating the e-mail addresses in such a way that for similarly starting names the resulting e-mail address would be different.<\/p>\n<p>Change your data array to the following:<\/p>\n<pre class=\"toolbar:1 lang:default highlight:0 decode:true\">char *data[] = {\"Maria,Kask\",\r\n                \"Johanna-Maria,Kask\",\r\n                \"Kalev,Kristjan,Kuusk\",\r\n                \"Margit,Kasemets\",\r\n                \"Maris,Kase\",\r\n                \"Marko,Kasvataja\",\r\n                \"Margus,Kasevee\"};<\/pre>\n<p><strong>Requirements<\/strong><\/p>\n<ul>\n<li>The e-mail addresses must be unique<\/li>\n<li>The name part of the address must be 6 characters<\/li>\n<li>The addresses must still refer to the owner&#8217;s name as much as possible<\/li>\n<li>The exact algorithm and thus the final form of the address is up to you. You will defend your decision when showing.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"After_this_lesson_you_should\"><\/span><strong>After this lesson, you should<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Know that there are various ways of encoding characters, including ASCII and Unicode<\/li>\n<li>Know what is an ASCII table and how to use it.<\/li>\n<li>Know how strings work in C.<\/li>\n<li>Know how to terminate a string in C and why it&#8217;s necessary.<\/li>\n<li>Know that strings in C are also related to byte-arrays.<\/li>\n<li>Know what is CSV, where it&#8217;s used and why.<\/li>\n<li>Know how to use the string.h library to manipulate strings.<\/li>\n<li>Be able to write your own string manipulation functions (manipulating characters)<\/li>\n<li>Know what is buffer overflow and the attacks related to it.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Additional_content\"><\/span><span id=\"Additional_content\" class=\"ez-toc-section\"><\/span><strong>Additional content<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Characters, Symbols and the Unicode Miracle &#8211; Computerphile<br \/>\n<strong><a href=\"https:\/\/www.youtube.com\/watch?v=MijmeoH9LT4\">https:\/\/www.youtube.com\/watch?v=MijmeoH9LT4<\/a><\/strong><\/li>\n<li>A beginners guide away from scanf<br \/>\n<strong><a href=\"https:\/\/www.sekrit.de\/webdocs\/c\/beginners-guide-away-from-scanf.html\">https:\/\/www.sekrit.de\/webdocs\/c\/beginners-guide-away-from-scanf.html<\/a><\/strong><\/li>\n<li>ASCII<br \/>\n<strong><a href=\"https:\/\/en.wikipedia.org\/wiki\/ASCII\">https:\/\/en.wikipedia.org\/wiki\/ASCII<\/a><\/strong><\/li>\n<li>ASCII table<br \/>\n<strong><a href=\"https:\/\/www.rapidtables.com\/code\/text\/ascii-table.html\">https:\/\/www.rapidtables.com\/code\/text\/ascii-table.html<\/a><\/strong><\/li>\n<li>Character encoding<br \/>\n<strong><a href=\"https:\/\/en.wikipedia.org\/wiki\/Character_encoding\">https:\/\/en.wikipedia.org\/wiki\/Character_encoding<\/a><\/strong><\/li>\n<li>String.h library<br \/>\n<strong><a href=\"https:\/\/www.cplusplus.com\/reference\/cstring\/\">https:\/\/www.cplusplus.com\/reference\/cstring\/<\/a><\/strong><\/li>\n<li>Strings in C<br \/>\n<strong><a href=\"https:\/\/www.geeksforgeeks.org\/strings-in-c-2\/\">https:\/\/www.geeksforgeeks.org\/strings-in-c-2\/<\/a><\/strong><\/li>\n<li>CSV<br \/>\n<strong><a href=\"https:\/\/en.wikipedia.org\/wiki\/Comma-separated_values\">https:\/\/en.wikipedia.org\/wiki\/Comma-separated_values<\/a><\/strong><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Lab materials Slides: Strings Sample:\u00a0Some simpler character assignments Lab tasks In this task you have two tasks. The first task focuses on using string.h library and reading input from the user. The second task looks at manipulating strings manually and introduces you to CSV (comma separated value) format. Task 1 [W13-1]: Introducing the string.h library &hellip; <a href=\"https:\/\/blue.pri.ee\/ttu\/labs\/pr1en13-strings\/\" class=\"more-link\">Loe edasi <span class=\"screen-reader-text\">PR1EN13: Strings<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[75,77],"tags":[],"class_list":["post-6501","post","type-post","status-publish","format-standard","hentry","category-labs","category-pr1_en"],"_links":{"self":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/posts\/6501","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/comments?post=6501"}],"version-history":[{"count":12,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/posts\/6501\/revisions"}],"predecessor-version":[{"id":10929,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/posts\/6501\/revisions\/10929"}],"wp:attachment":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/media?parent=6501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/categories?post=6501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/tags?post=6501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}