Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am using .wav extension 3) The header for the wav file is 44 bytes long; decla

ID: 3911137 • Letter: I

Question

I am using .wav extension

3) The header for the wav file is 44 bytes long; declare a char pointer called header char * header; and malloc( ) 44 bytes to hold the header . Use fread( ) to read-in ALL of the header information into the malloc'd header using a single fread( ) statement.

Declare pointers of the appropriate data type for each piece of information in the wav header. For example, you might use char * chunkid; unsigned int * chunksize; char * format; char * subchunk1id; unsigned int * subchunk1size; unsigned short int * audioformat; etc.

Point each of the pointers in (4) to the appropriate locations in the 1-D array header. Make sure to include an explicit cast from the char pointer location in header to a pointer of the appropriate data type for each particular piece of information in the header. . For example: chunkid=header; // both are char pointers, so no cast is necessary. chunksize=(int *)(header +4); // Chunksize is information in 4-bytes denoting a non-negative size of the chunk. // chunksize is an int pointer, not a char pointer like header. format=header+8; // both are char pointers, so no cast is necessary subchunk1id=header+12; // both are char pointers, so no cast is necessary subchunk1size=(int *)(header+16); etc.

Print out ALL of the audio file characteristics to the screen using the pointers you declared in (4). Dereference each pointer to the value to which it points. For example, printf(" %c%c%c%c ",*chunkid,*(chunkid+1),*(chunkid+2),*(chunkid+3)); would print out 4 characters to the screen. It should show "RIFF". If you try to use a string format for this, there is a problem trying to restrict the printf() statement to no more than 4 characters, because header[4] is not equal to '' the string termination character.

http://wavefilegem.com/how_wave_files_work.html

Explanation / Answer

//1) Answer for 3rd Question.

//This program is a subroutine function to check the extension of a given file is in WAV format or not.

// if provided filename is in WAV format then this will return 1 else return 0 and it promts untill the provided filename was in WAV format

#include<stdio.h>
#include<string.h>
#include<ctype.h>
int check_extension(const char *filename)
{
//strrchr returns a last pointer occurrence of character as we require extension with .
char *extension = strrchr(filename, '.')+1;
char a[10];
int i=0;
//Taking all the extension Characters in lowercase as we accept the file in .wav or .WAV or .WaV
while(*extension!='')
{
a[i]=tolower(*extension);
extension++;
i++;
}
char *ex="wav";
//Comparing whether the extension is in wav format.
if(strcmp(a,ex)==0)
{
for(i=0;a[i]!='';i++)
a[i]='';
printf("");
return 1;
}
else
{
for(i=0;a[i]!='';i++)
a[i]='';
printf("");
return 0;
}
}
void main()
{
//Assuming Maximum Length of filename is 100 Characters
char filename[100];
//Reading the Filename
printf("Enter Filename:");
scanf("%s", &filename);
//Checking till the file contains .wav format
while(check_extension(filename)==0)
{
printf("Enter the correct Filename in WAV format:");
scanf("%s", &filename);
}
printf("Correct File is %s",filename);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote