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...
How do I write a program in MIPs assembly that will take 2 words from the user and check if they're in a string. For example: String: " A B Cat C Dog D E Cat cAT Owl Ferret" User input: Word 1: Owl Word 2: Cat OUTPUT: Owl- 1 time(s) Cat: 3 time(s) Owl- # Cat-###
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
Debug following methods(longestRun(finds how many times a character got repeated), findLastP(finds last p in a string), findFirstP(finds first p in a string)) in java language. public class simpleLoops { /** * @param args */ public static void main(String[] args) { System.out.println(longestRun("aabbbccd")); System.out.println("Expected 3"); System.out.println(longestRun("aaa")); System.out.println("Expected 3"); System.out.println(longestRun("aabbbb")); System.out.println("Expected 4"); int count = countP("Mississippi"); System.out.println(count); int result = findLastP("Mississippi"); System.out.println(result); result = findFirstP("stop"); System.out.println(result); result = findFirstP("xxxyyyzzz"); System.out.println(result); } /** *...
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)
C Program: How do I display if the input is invalid for input not in the range from (1-10); #include <stdio.h> int main(){ int number,i; // prompt user to enter number of lines to print Bad Dog printf("Enter a number of lines to print Bad Dog:"); scanf("%d",&number); for(i=0;i<number;i++){ goto nonono; nonono: printf("Bad Dog\n"); } return 0; }// end main
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.
Programming challenge description: Write a program that, given two clock times, prints out the absolute number of minutes between them. Input: Your program should read lines from standard input. Each line contains two wall clock times separated by a hyphen. Wall clock time is defined as hh:mm followed by AM' or 'PM', e.g. '09:05 AM' Output: Print to standard output the number of minutes between the two times from standard input. Print out each result on a new line. Test...
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....
I am unsure on how to do this (java language) The program you must write needs to perform the following. 1. Read from stdin(System.in), up to 100 whitespace separated words, and store them in a data structure of your choice. 2. Calculate the average word length. 3. Print each word which is greater than the average length, in the reverse order thatthey were read in. 4. Print "Average: "followed the average word length to two decimal places. 5. If no...