Question

Write a program to implement the following requirement: The program will read from standard input any text up to 10, 900, cha
write a program in C
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hello, I have written the required code in C. Please find it below.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>


struct Node
{
   char word[1000];
   struct Node * next;
};
struct Node * START=NULL;

struct Node * createNode(char * data)
{
   struct Node * temp=(struct Node *)malloc(sizeof(struct Node));
   strcpy(temp->word,data);
   temp->next=NULL;
   return temp;  
}
void insert(char * data)
{
struct Node * temp=createNode(data);
   struct Node *a=START;
   if(START==NULL)
   {
       START=temp;
   }
   else
   {
       while(a->next!=NULL)
       {
           a=a->next;
       }
       a->next=temp;
   }
}

int isExist(char * data)
{
struct Node *a=START;
   int flag=0;
   while(a!=NULL)
   {
       if(strcmp(a->word,data)==0)
       {
           flag=1;
           break;
       }
       a=a->next;
   }
   if(flag==0)
   return 0;
   return 1;
}

void display()
{
   struct Node *a=START;
   while(a->next!=NULL)
   {
       printf("%s, ",a->word);
       a=a->next;
    }
   printf("%s",a->word);
  
}
int main()
{
   char str[1000];
   char word[1000];
   gets(str);
   int i,j=0,k;
   for(i=0;str[i]!='\0';i++)
   {
   if(str[i]==32)
   {
       k=0;
           while(j<i)
           {
               word[k]=str[j];
               k++;
               j++;
           }
           word[k]='\0';
           j++;
           if(!isExist(word))
           {
           insert(word);  
           }
       }  
   }
           k=0;
           while(j<i)
           {
               word[k]=str[j];
               k++;
               j++;
           }
           word[k]='\0';
           j++;
           if(!isExist(word))
           {
           insert(word);  
           }
display();
return 0;
}

Ouput:-

C:\Users\Dell india\Desktop\B.exe line line word hello word line whatever here line, word, hello, whatever, here

I hope it would be helpful.

Thanks!

Add a comment
Know the answer?
Add Answer to:
write a program in C Write a program to implement the following requirement: The program will...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 2 Write a program that will read in a line of text up to 100...

    Question 2 Write a program that will read in a line of text up to 100 characters as string, and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by whitespace, a period, a comma, or the beginning or end of the line. You can assume that the input consists entirely of letters, whitespace, commas, an<d periods. When...

  • C++ NEED HELP WITH MY REVERSE STRING FUNCTION IN LINK LIST A function Reverse, that traverses...

    C++ NEED HELP WITH MY REVERSE STRING FUNCTION IN LINK LIST A function Reverse, that traverses the linked list and prints the reverse text to the standard output, without changing the linked list. ( Pass the linked list by value, you have the freedom to create a doubly linked list that is a copy of the original list in your program before you call the function) #include "pch.h" #include <iostream> #include <string.h> #include <string> using namespace std; #define MAX 512...

  • Am Specification For this assignment, you will write a multi-file C program to define, implement ...

    Must be written and C, and compile with MinGW. Thank you! am Specification For this assignment, you will write a multi-file C program to define, implement and use a dynamic linked lists. Please refer to Lab 07 for the definition of a basic linked list. In this assignment you will need to use the basic ideas of a node and of a linked list of nodes to implement a suit of functions which can be used to create and maintain...

  • In this lab you will write a spell check program. The program has two input files:...

    In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the document to be spellchecked. The program will read in the words for the dictionary, then will read the document and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is or type in a replacement word and add...

  • Write a program, called wordcount.c, that reads one word at a time from the standard input....

    Write a program, called wordcount.c, that reads one word at a time from the standard input. It keeps track of the words read and the number of occurrences of each word. When it encounters the end of input, it prints the most frequently occurring word and its count. The following screenshot shows the program in action: adminuser@adminuser-VirtualBox~/Desktop/HW8 $ wordCount This is a sample. Is is most frequent, although punctuation and capitals are treated as part of the word. this is...

  • Create Functions for the following prototypes. Below is the setup.*program is in c* #include <stdio.h> #include...

    Create Functions for the following prototypes. Below is the setup.*program is in c* #include <stdio.h> #include <string.h> #include <stdarg.h> #include <stdlib.h> //#define constant values #define MAX_URL_LENGTH 50 #define TRUE 1 #define FALSE 0 //typedef for the Element struct which constains a c string to store a URL in the BrowserList typedef struct { char szURL[MAX_URL_LENGTH]; } Element; //Typedef for a node in the doubly linked list (has next and previous pointers). typedef struct NodeDL { Element element; struct NodeDL *pNext;...

  • C Programming Language on Linux - Word Frequency Program Please write a Program in C that...

    C Programming Language on Linux - Word Frequency Program Please write a Program in C that will accept a text file name as a command-line argument via a main program that will do the following: First, read the file (first pass) and create a linked list of words (in their order of occurrence), with the frequency of each word set to 0. Then, read the file (second pass) and for each word identified, search the linked list, and when found,...

  • C++ (1) Write a program to prompt the user for an input and output file name....

    C++ (1) Write a program to prompt the user for an input and output file name. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs. For example, (user input shown in caps in first line, and in second case, trying to write to a folder which you may not have write authority in) Enter input filename: DOESNOTEXIST.T Error opening input file: DOESNOTEXIST.T...

  • Problem 1. Implement a C++ program that has the following functions: Reads in a paragraph of...

    Problem 1. Implement a C++ program that has the following functions: Reads in a paragraph of English text up to 100 words from the keyboard and stores this paragraph in a string object. Feel free to include this task in the main() function. Identifies the least frequent letter (case insensitive) in the above paragraph. Implement a separate function getLeastFreqLetter() for this task. The main() function then calls this function to find out the least frequent letter and its frequency. Calculate...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT