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

read_line function is as follows: int read_line(FILE *fp, char *str, int n) { in

ID: 3738452 • Letter: R

Question

read_line function is as follows:

int read_line(FILE *fp, char *str, int n)
{
int ch, i =0;
while ((ch = fgetc(fp)) != ' ')
{
// printf("%c", ch);
if (i < n)
*str++ = ch;
}
*str= '';

return i;
}

Project 7 Extra credit (40 points) Write a program that reads in a line of text, and display the acronyms in the sentences. The input are assumed be line of English words separated by white spaces comma, period, or exclamation point. The output contains the list of acronyms in the nput. lhe list of acronyms you will search for TBH, BRB, LOL, IDK, TTYL, IRL, TIA, AFK, CYA, FYI, OMG For example Input: TBH, 1DK ?f my hashtag will end up trending or if anyone will even like it. It will only be viral if people can relate to it IRL Output: TBH IDK IRL 1) 2) Assume input is no longer than 1000 characters. Assume the input contains no 3) You may find string library functions such as strtok, strcmp, and 4) To read a line of text, use the readline function in the lecture notes Name your program words.c. more than 500 words. Assume each word is no more than 50 characters. strcpy helpful.

Explanation / Answer

This code will work for delimiters space and comma...

I'm giving you three functions main(), and your read_line(), and one split() function.

I have given the input directly as char *s = "TBH IDK if my has IRL something like CYA";

3 functions:

#include<stdio.h>

#include<sys/types.h>

#include<sys/file.h>

#include<unistd.h>

int read_line(FILE *fp, char *str, int n)

{

int ch, i =0;

while ((ch = fgetc(fp)) != ' ')

{

// printf("%c", ch);

if (i < n)

*str++ = ch;

}

*str= '';

return i;

}

int split (const char *str, char c, char ***arr)

{

int count = 1;

int token_len = 1;

int i = 0;

char *p;

char *t;

p = str;

while (*p != '')

{

if (*p == c)

count++;

p++;

}

*arr = (char**) malloc(sizeof(char*) * count);

if (*arr == NULL)

exit(1);

p = str;

while (*p != '')

{

if (*p == c)

{

(*arr)[i] = (char*) malloc( sizeof(char) * token_len );

if ((*arr)[i] == NULL)

exit(1);

token_len = 0;

i++;

}

p++;

token_len++;

}

(*arr)[i] = (char*) malloc( sizeof(char) * token_len );

if ((*arr)[i] == NULL)

exit(1);

i = 0;

p = str;

t = ((*arr)[i]);

while (*p != '')

{

if (*p != c && *p != '')

{

*t = *p;

t++;

}

else

{

*t = '';

i++;

t = ((*arr)[i]);

}

p++;

}

return count;

}

int main (int argc, char ** argv)

{

int i,j,k;

char *s = "TBH IDK if my has IRL orij oij CYA";

int c = 0;

char **arr = NULL;

c = split(s, ' ', &arr);

const char* acr[11]={"TBH","BRB","LOL","IDK","TTYL","IRL","TIA","AFK","CYA","FYI","OMG"};

for(i=0;i<11;i++)

{

for(j=0;j<c;j++)

{

if(strcmp(acr[i],arr[j])==0)

printf("%s ",arr[j]);

}

}

c = split(s, ',', &arr);

for(i=0;i<11;i++)

{

for(j=0;j<c;j++)

{

if(strcmp(acr[i],arr[j])==0)

printf("%s ",arr[j]);

}

}

return 0;

}