Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/ / PROBLEM 2 : Uses print _ fontified _ oneline ( ) with find _ linebreaks ( ) to / / correctly print '

// PROBLEM 2: Uses print_fontified_oneline() with find_linebreaks() to
// correctly print 'msg' with 'font' even if there are linebreaks in
//'msg'. Uses find_linebreaks() to find the end of each line in
//'msg' and then iterates over lines printing each. Uses pointer
// arithmetic to pass the starting position of each line into calls of
// print_fontified_oneline(). Frees memory allocated (such as through
// use of count_linebreaks()) before returning.
//
// EXAMPLE:
// print_fontified("apple
B@N@N@
Carr0^", &font_standard);
// Shows the following on standard output:
//,-,
//___,___.,___.||___
///_`||'_\|'_\||/'_`\
//|(_||||_)|||_)||||__/
//\__,_||.__/|.__/|_|\___|
//|_||_|
//,________._._.____._._.____
//|==)/__\|\||/__\|\||/__\
//|_\//_`||\||//_`||\||//_`|
//||_)|||(_||||\|||(_||||\|||(_||
//|____/\\__,.||_|\_|\\__,.||_|\_|\\__,.|
//\____/\____/\____/
//____.___/\
///___|___.___..___./_\|/\|
//||/_`||`__||`__|||||
//||___.|(_||||||||_||
//\____|\__,_||_||_|\___/
void print_fontified(char *msg, font_t *font){
// PROVIDED: Initializes a glyph to mostly X's except for its
// codepoint on the first line.
void glyph_init(glyph_t *glyph, int codepoint){
glyph->codepoint = codepoint;
glyph->width =6;
for(int i=0; iwidth){
glyph->data[i][j]='\0'; // null terminate
}
else{
glyph->data[i][j]='X';
}
}
}
int len = sprintf((char *)glyph->data, "%d",codepoint); // add codepoint # to glyph
glyph->data[0][len]='X'; // remove null termination char
}
// PROBLEM 2: Loads a banner font from 'filename'. The format of font
// files is documented more thoroughly in the project specification
// but is generally comprised of a first line that indicate the height
// of each glyph in the font followed by a sequence of each glyph
// starting with its codepoint (ASCII index) and a grid of characters
// in it. To make parsing easier, the ? character is used to represent
// blank spaces in glyph shapes.
//
// EXAMPLE:
// height: 4
//42
//???
//\|/
///|\
//???
//43
//???
//_|_
//?|?
//???
//
// The two characters above are the codepoint 42'*' and codepoint 43
//'+' with the ? symbols eventually being replaced by spaces during
// loading.
//
// If 'filename' cannot be opened for reading, returns NULL.
//
// Memory allocation happens in two steps: (1) allocates memory for a
// font_t struct then (2) allocates memory for an array of glyph_t
// structs of length NUM_ASCII_GLYPHS (a constant defined in
// banlet.h). Sets the font->glyphs field to be the allocated array of
// glyphs. Reads the font->height field from teh first line of the
// file. Iterates over each element of the glyphs array and calls the
// glyph_init() function on it to populate it with default data. Then
// proceeds to read glyphs from the file. Glyphs are read by reading
// the integer codepoint first which determins which element of the
// glyph array to read into. Then a loop over the height of the font
// is used to read each row of the glyph into the
// glyph[codepoint]->data[row]; fscanf() with '%s' specifier is used
// for this. Finally, the string_replace_char() function is used to
// replace all '?' characters with ''(space) characters in the glyph
// data. Sets the width of each glyph using the strlen() function on
// any balid row of the glyph data.
//
// Glyphs are read from 'filename' until an attempt to read a glyph's
// codepoint with fscanf() returns EOF (end of file). This causes the
// routine to return the allocated font_t data for use elsewhere.
font_t *font_load(char *filename){
// WRITE ME
return NULL;
}
// PROBLEM 2: Frees the memory associated with 'font'. First frees
// the glyph array, then frees the font itself. Hint: this funciton
// should be 2 lines long.
void font_free(font_t *font){
// WRITE ME
}
// PROBLEM 2: Read all characters from the file 'filename' into a
// dynamcally allocated array. Terminates the array with the '\0'
// character to form a valid C string and return that string. If the
// file cannot be opened, return NULL.
//
// CONSTRAINT: Does not use any functions that determine the size of a
// file a priori such as fstat() or fseek() or their kin.
//
// BASELINE: Uses a "2-Pass" solution. Counts the characters in file
// via calls to fscanf() or fgetc(), then returns to beginning of the
// file with rewind(), allocates an appropriately sized block of
// memory, then reads all characters into it in a second pass.
//

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Perform an Internet search. Discuss a company that uses EPLI.

Answered: 1 week ago

Question

How do you feel about employment-at-will policies? Are they fair?

Answered: 1 week ago