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

CAN ANYONE PLEASE HELP ME WITH NUMBER 2 AND 3?? Please explain your codes and re

ID: 3731935 • Letter: C

Question

CAN ANYONE PLEASE HELP ME WITH NUMBER 2 AND 3?? Please explain your codes and review the expected output.

I don't think proj4.txt file is needed to do number 2 and 3, but I screenshot it just in case.

I'll give thumbs up if anyone could correctly help me. THANKS IN ADVANCE!

1 The different color components are surrounded with colored boxes. The BITMAPHEADER and BITMAPINFOHEADER bytes are surrounded by black boxes 2The four pixels are surrounded by a box of the same color and the padding bytes are surrounded by purple boxes 3Note that the pixels are stored in this order: blue, yellow (the bottom row of the image), red, green (the top row of the image) proj4.txt X the vlue, tore edo Note also that the RGB components of each pixel are stored in GBR order and the number of padding bytes on each raw is 2 5 As each row has two pixells, which takes six bytes, and we need to add two padding bytes to make each row 8 bytes, in order to be multiple of 4.

Explanation / Answer

#include <stdio.h>

#include <stdbool.h>

#define MAXCHAR 1000

void wordCount()

{

int i=0;

FILE *fp;

char str[MAXCHAR];

fp = fopen("test.txt", "r");

int count=0;

bool foundLetter=false;

while (fgets(str, MAXCHAR, fp) != NULL)

{

  

for (i = 0;i<strlen(str);i++)

{

if (s[i] == ' ')

foundLetter = false;

else

{   

if (foundLetter == false)

count++;

foundLetter = true;

}

}

  

fclose(fp);

}

void findAndReplace()

{

FILE *fp;

char str[MAXCHAR];

char find[30],replace[30];

char stringToWrite[MAXCHAR*10];

printf("Enter the word find for replacement: ");

scanf("%s", find);

printf(" Enter the replacement word of equal length: ")

scanf("%s",replace);

printf(" ");

fp = fopen("test.txt", "r+");

int count=0;

bool foundLetter=false;

char *result = NULL;

while (fgets(str, MAXCHAR, fp) != NULL)

{

result=replaceWord(str, find, replace);

strcat(stringToWrite,result);

result=NULL:

}

  

fclose(fp);

fp = fopen("test.txt", "w");

fprintf(fp,"%s", stringToWrite);

fclose(fp);

}

char *replaceWord(const char *s, const char *oldW,

const char *newW)

{

char *result;

int i, cnt = 0;

int newWlen = strlen(newW);

int oldWlen = strlen(oldW);

// Counting the number of times old word

// occur in the string

for (i = 0; s[i] != ''; i++)

{

if (strstr(&s[i], oldW) == &s[i])

{

cnt++;

// Jumping to index after the old word.

i += oldWlen - 1;

}

}

// Making new string of enough length

result = (char *)malloc(i + cnt * (newWlen - oldWlen) + 1);

i = 0;

while (*s)

{

// compare the substring with the result

if (strstr(s, oldW) == s)

{

strcpy(&result[i], newW);

i += newWlen;

s += oldWlen;

}

else

result[i++] = *s++;

}

result[i] = '';

return result;

}

int main()

{

wordCount();

findAndReplace();

}

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