How do I write a C program that finds how many times a word is used in a string and prints the result. The string is hardcoded. How do I also make it print the hashes?
For instance: String: " Dog Cat Owl Ferret Rabbit Cat Dolphin Penguin Cat"
Word 1: Owl
Word 2: Cat
Desired Output:
Owl- 1 time(s)
Cat: 3 time(s)
Owl- #
Cat-###
#include <stdio.h>
#include <string.h>
/* Function declaration */
int counting(char * s, char * w);
int main()
{
char str[500];
char substr[100];
int count;
/* Input string and word from user */
printf("Enter main string: ");
fgets(str,500, stdin);
/*do while loop to search for words continuously*/
while(1){
int k=0;
printf("Enter word to search: ");
/*scanf("%s",&substr);*/
gets(substr);
count = counting(str, substr);
printf("%s -",substr);
for(k=0;k<count;k++)
{
printf("#");
}
printf("\n");
}
return 0;
}
/**
* Get, total number of occurrences of a word in a string
*/
int counting(char *s,char *w)
{
int n,a[1000],i,j,k=0,l,count=0,t=0;
for(i=0;s[i];i++)
{
if(s[i]==' ')
{
a[k++]=i;
}
}
a[k++]=i;
j=0;
for(i=0;i<k;i++)
{
n=a[i]-j;
if(n==strlen(w))
{
t=0;
for(l=0;w[l];l++)
{
if(s[l+j]==w[l])
{
t++;
}
}
if(t==strlen(w))
{
count++;
}
}
j=a[i]+1;
}
return count;
}
How do I write a C program that finds how many times a word is used...
programming language must be in BASIC Write a program that finds how many times a prime number is obtained when a dice is tossed 100 times.
Write a program that will allow the user to specify how many times the program will loop and display the title of the program include your name in the title, print from in the loop a string and count. -Assembly Language MASM 8086
how do i return and array of string (2d array) from a single linkedlist in c? for example i have a linkedlist that contains cat->dog->dish how do i return them to main as an array (cat,dog,dish)
Please do it with C++. Thanks:) Write a program that reads a string and a character from the keyboard. The program should output how many times the character appears in the string. Make the program run in a loop until the string finish is input. Sample run: Input a string: alicia Input a letter: a The letter appears 2 times Input a string: felix Input a letter: x The letter appears 1 time Input a string: finish Good Bye.
Description: Overview: You will write a program (says wordcountfreq.c) to find out the number of words and how many times each word appears (i.e., the frequency) in multiple text files. Specifically, the program will first determine the number of files to be processed. Then, the program will createmultiple threads where each thread is responsible for one file to count the number of words appeared in the file and report the number of time each word appears in a global linked-list....
Write MARIE assembly language programs that do the following: I. Write a program that inputs three integers, a, b, and c, in that order. It computes the following ia-bi-fc+ c The result should be written to output 2. Write a program that inputs integers, s. y, and z. It outputs the difference of the langest and first element entered. You may assume x. y, and z all have different values. So if 8, 12, and 9 are input, the output...
hey dear i just need help with update my code i have the hangman program i just want to draw the body of hang man when the player lose every attempt program is going to draw the body of hang man until the player lose all his/her all attempts and hangman be hanged and show in the display you can write the program in java language: this is the code bellow: import java.util.Random; import java.util.Scanner; public class Hangmann { //...
P1) Write a complete C program that prints out the word YES, if its string command line argument contains the sequence the somewhere in it. It prints out the word NO otherwise. Both the word the and partial sequences like in the words theatre or brother qualify. Note: You can use string functions or not but if you do the only ones allowed are strcpy and strlen. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P2) What is the output of the following program (one answer per...
I need all parts with MATLAB programming .i have part A already 3. Speed Reader (Adapted from http://ni stanford.edu/2015 /poser a-s -reader This project requires you to create a program that takes two inputs: o A string of any length. o A number of words per minute. Your program will take the string, break it up into individual words, and display it one word at a time at the desired rate. For instance, "Hello World!" at 500 words per minute...
C++ Write a program that asks for a number and then prints as many lines as the user inputs. Each line contains as many pairs of characters ("*#") as the number of this line. It should look like the right half of a pyramid. Your version of the program must print the same result as the expected output. To to this lab, you must use two do-while loops. Two exceptions: When the user inputs a number less than 1, then...