Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ / PROBLEM 2 : Uses print _ fontified _ oneline ( ) with find _ linebreaks ( ) to / / correctly print '
PROBLEM : Uses printfontifiedoneline with findlinebreaks to
correctly print msg with 'font' even if there are linebreaks in
msg Uses findlinebreaks 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
printfontifiedoneline Frees memory allocated such as through
use of countlinebreaks before returning.
EXAMPLE:
printfontifiedapple
B@N@N@
Carr &fontstandard;
Shows the following on standard output:
void printfontifiedchar msg fontt font
PROVIDED: Initializes a glyph to mostly Xs except for its
codepoint on the first line.
void glyphinitglypht glyph int codepoint
glyphcodepoint codepoint;
glyphwidth ;
forint i; iwidth
glyphdataij; null terminate
else
glyphdataijX;
int len sprintfchar glyphdata, dcodepoint; add codepoint # to glyph
glyphdatalenX; remove null termination char
PROBLEM : 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:
The two characters above are the codepoint and codepoint
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: allocates memory for a
fontt struct then allocates memory for an array of glypht
structs of length NUMASCIIGLYPHS a constant defined in
banlet.h Sets the fontglyphs field to be the allocated array of
glyphs Reads the fontheight field from teh first line of the
file. Iterates over each element of the glyphs array and calls the
glyphinit 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
glyphcodepointdatarow; fscanf with s specifier is used
for this. Finally, the stringreplacechar 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 glyphs
codepoint with fscanf returns EOF end of file This causes the
routine to return the allocated fontt data for use elsewhere.
fontt fontloadchar filename
WRITE ME
return NULL;
PROBLEM : Frees the memory associated with 'font'. First frees
the glyph array, then frees the font itself. Hint: this funciton
should be lines long.
void fontfreefontt font
WRITE ME
PROBLEM : Read all characters from the file 'filename' into a
dynamcally allocated array. Terminates the array with the
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 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
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