Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can someone help me with making this program? This has to be done in C language. For this assignment, we want to write a function
Can someone help me with making this program?
This has to be done in C language.
For this assignment, we want to write a function that formats/justifies a string. The signature of the function should look like: void formatAndPrintParagraph(char *paragraph, int lineLength); Very important: You should make sure to use this exact signature. Let's look at some examples first! 1) paragraph = "Hi everyone. This is the 2nd assignment. Please make sure you start early as this is going to take some time!" line Length = 25 output should be: Hi everyone. This is the 2nd assignment. Please make sure you start early this is going to take some time! as 2) paragraph = "Hi everyone. This is the 2nd assignment. Please make sure you start early as this is going to take some time!" lineLength = 40 output should be: Hi everyone. This is the 2nd assignment. Please make sure you start early as this is going to take some time! So, what is this output? Basically, we want to break the paragraph into lines of equal length (parameter lineLength). We also want to make sure the number of spaces we add in between words are balanced. For example if your line length is 30 and on your first line you have four words with sizes: 7, 4, 8 and 3 you need to add 3 spaces between first word and second word, three spaces between second word and third word and finally two spaces between third word and fourth word. Your line's length would add up to: 7 (first word) + 3 spaces + 4 (second word) + 3 spaces + 8 (third word) + 2 spaces + 3 (fourth word) = 30. Here are some assumptions you can make: Maximum number of words in the paragraph = 100 Maximum length of a word = 20 Hint! I wrote this program myself. Here are the functions that I have in my code. Please note that I am providing these as help for you to start your program. You don't necessarily need to have these exact functions: #define MAX_WORD_LENGTH 20 #define MAX_NUMBER_OF_WORDS 100 char *move ToBeginning OfNextToken(char *inputString), Int getCurrentTokenSize(char *inputString); Int tokenize(char * paragraph, char tokens[MAX_NUMBER_OF_WORDS][MAX_WORD_LENGTH]); int getNumberOfWordsForNextLine(char tokens[MAX_NUMBER_OF_WORDS][MAX_WORD_LENGTH], int numberOfWords Processed SoFar, int totalNumberOfWords, int lineLength); void printWordAndSpaces(char word[MAX_WORD_LENGTH), int numberOfSpaces) void formatAndPrintCurrentLine(char tokens[MAX_NUMBER_OF_WORDS][MAX_WORD_LENGTH), int numberOfWordsProcessed SoFar, int numberOfWordsOnNextLine, int lineLength); void formatAndPrintWords(char tokens[MAX_NUMBER_OF_WORDS][MAX_WORD_LENGTH], int totalNumberOfWords, int lineLength); void formatAndPrintParagraph(char *paragraph, int lineLength); Let's see what each of these is supposed to do: moveToBeginning OfNextToken: Takes a string and moves the pointer to the first non-blank character (or end of the string if there is no non-blank character). getCurrentToken Size: given a string with no leading spaces, returns the size of the first word. For example, if the string is Hello world", it should return 5. tokenize: given the paragraph, it breaks it down into words. Stores the words in the given tokens array of string. For example, for paragraph = "Hi. How is it going? Thanks." This function would fill the tokens array to be like this: tokens[0] = "Hi.", tokens[1] = "How, tokens[3] = "is" and so on. getNumberOfWordsForNextLine: Given the array of tokens (words), number of words that we have processed so far, total number of words (size of the string array) and line length (from the formatAndPrintParagraph function): It returns the number of words that needs to be printed on the next line. print WordAnd Spaces: This function simply prints a string followed by some number of spaces (no new line) formatAndPrintCurrentLine: Given the tokens/words, number of words printed so far, number of words that needs to be printed on the next line and line length, this function basically prints one line of the output. formatAndPrint Words: You would call this function after you have tokenized the input paragraph. This function basically formats words in a string array (tokens) on lines of length lineLength. The function that this formatAndPrintParagraph: assignment is asking for! Notes: In your main() function, add a lot of unit test to cover as many (edge) cases as you can think ofStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started