Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I will provide a new ppm_utils.h file that includes the functions you will need to implement. Outlined below are several functions you MUST write. 1.
I will provide a new ppm_utils.h file that includes the functions you will need to implement. Outlined below are several functions you MUST write. 1. void skip ws comments(FILE* infileptr); This function will be used when you are reading the header of the ppm files. As discussed in class, ppm headers can and often do have comments embedded within them. A header will not have a comment before the "Magic Number" - P6 or P3. A comment can be on the same line as the Magic Number. As an example: PG #Hello world A comment will always end with a new line characters. Therefore, you will not have something like the following: 200 200 #Hello Again 255 Comments can be on a line by itself. #hello wold Here is an example header with comments and spaces: P3 #Hello world, this is a comment #Next will be a set of blank spaces and then the width 200 #And another comment 200 255 Your function should ignore these comments and extra white spaces. Here are the suggested steps needed for this function. Use the c function fgetc to read a character. check to see if the character read in step 1 is a # or space. You can test for a space using the "C" function isspace. If it is a space then continue reading, using fgetc, until it is no longer a space. Once you determine the character is no longer a space you need to move the pointer back to the previous character (remember we discussed in class what happens when you read something from a file using a file pointer) You can move the pointer back by using the function ungetc. Ungetc is the equivalent of putting the character back so it can be read again during the next read cycle. I will provide a new ppm_utils.h file that includes the functions you will need to implement. Outlined below are several functions you MUST write. 1. void skip ws comments(FILE* infileptr); This function will be used when you are reading the header of the ppm files. As discussed in class, ppm headers can and often do have comments embedded within them. A header will not have a comment before the "Magic Number" - P6 or P3. A comment can be on the same line as the Magic Number. As an example: PG #Hello world A comment will always end with a new line characters. Therefore, you will not have something like the following: 200 200 #Hello Again 255 Comments can be on a line by itself. #hello wold Here is an example header with comments and spaces: P3 #Hello world, this is a comment #Next will be a set of blank spaces and then the width 200 #And another comment 200 255 Your function should ignore these comments and extra white spaces. Here are the suggested steps needed for this function. Use the c function fgetc to read a character. check to see if the character read in step 1 is a # or space. You can test for a space using the "C" function isspace. If it is a space then continue reading, using fgetc, until it is no longer a space. Once you determine the character is no longer a space you need to move the pointer back to the previous character (remember we discussed in class what happens when you read something from a file using a file pointer) You can move the pointer back by using the function ungetc. Ungetc is the equivalent of putting the character back so it can be read again during the next read cycle
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