A program to print out a word that appears the most number of times

Thread Solved

Join Date: Nov 2007
Posts: 24
Reputation: kiel19 is an unknown quantity at this point 
Solved Threads: 0
kiel19 kiel19 is offline Offline
Newbie Poster

A program to print out a word that appears the most number of times

 
0
  #1
Nov 18th, 2007
Write a program to find the number of times that a given word(i.e. a short string) occurs in the sentence(i.e. in a sentence!).

Read data from the standard input. the first line is a single word, which is followed by general text on the second line. read both up to a newline character, and insert a terminating null before processing.

Typical output should be:
The word is "the".
The sentence is "the cat sat on the mat".
The word occurs 2 times.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 514
Reputation: Jishnu will become famous soon enough Jishnu will become famous soon enough 
Solved Threads: 26
Jishnu's Avatar
Jishnu Jishnu is offline Offline
Posting Pro

Re: A program to print out a word that appears the most number of times

 
0
  #2
Nov 18th, 2007
Atleast show your code (efforts) & specify where you are stuck up. You are expecting that someone will write the entire code for you. You've not even specified what your specific problem is about.


Originally Posted by kiel19 View Post
Write a program to find the number of times that a given word(i.e. a short string) occurs in the sentence(i.e. in a sentence!).

Read data from the standard input. the first line is a single word, which is followed by general text on the second line. read both up to a newline character, and insert a terminating null before processing.

Typical output should be:
The word is "the".
The sentence is "the cat sat on the mat".
The word occurs 2 times.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 24
Reputation: kiel19 is an unknown quantity at this point 
Solved Threads: 0
kiel19 kiel19 is offline Offline
Newbie Poster

Re: A program to print out a word that appears the most number of times

 
0
  #3
Nov 18th, 2007
Originally Posted by Jishnu View Post
Atleast show your code (efforts) & specify where you are stuck up. You are expecting that someone will write the entire code for you. You've not even specified what your specific problem is about.
my code is here , you can help in modifying it to answer the question;
Help me on how to print the names , average mark and comment in descending order.

******************************************************
*******************************************************
  1. #include <stdio.h>
  2. int N;
  3. float array[3];
  4.  
  5. //declaration of structure
  6. struct marks{
  7. char first_name[20];
  8. char second_name[20];
  9. float CSC_2100;
  10. float CSC_2101;
  11. float CSC_2102;
  12. float CSC_2103;
  13. float CSC_2104;
  14. };
  15. struct marks student[5];
  16. // code to compute average
  17. float find_average( float a, float b,float c,float d,float e){
  18. float average = ((a+b+c+d+e)/5);
  19. return average;
  20. }
  21. // to sort the average marks in descending order
  22. void bubblesort(float a[], int N)
  23. {
  24. int i, swapped = 1;
  25. while(swapped)
  26. for (swapped = 0, i = 1; i<N; i++)
  27. if (a[i] > a[i-1]) {
  28. int t = a[i-1];
  29. a[i-1]=a[i];
  30. a[i]=t;
  31. }
  32. }
  33.  
  34.  
  35. int i;
  36. main()
  37. {
  38. printf("Enter marks for five students:\n\n");
  39. printf("Enter your marks as floats:");
  40. for (i = 0;i < 3; i++){
  41. printf("\n\n");
  42. printf("Enter your First name:");
  43. scanf("%s",&student[i].first_name);
  44. printf("Enter your Second Name:");
  45. scanf("%s",&student[i].second_name);
  46. printf("Enter marks for CSC 2100:");
  47. scanf("%f",&student[i].CSC_2100);
  48. printf("Enter marks for CSC 2101:");
  49. scanf("%f",&student[i].CSC_2101);
  50. printf("Enter marks for CSC 2102:");
  51. scanf("%f",&student[i].CSC_2102);
  52. printf("Enter marks for CSC 2103:");
  53. scanf("%f",&student[i].CSC_2103);
  54. printf("Enter marks for CSC 2104:");
  55. scanf("%f",&student[i].CSC_2104);
  56.  
  57. }
  58. for (i =0; i<3; i++){
  59. printf("\n\n");
  60. printf("Name :\t%s %s",student[i].second_name,student[i].first_name);
  61. printf("\nAverage: %.2f\t",find_average(student[i].CSC_2100,student[i].CSC_2101,student[i].CSC_2102,student[i].CSC_2103,student[i].CSC_2104));
  62. printf("\nRemark:\t");
  63. }
  64. for (i = 0; i<3;i++)
  65. array[i]= find_average(student[i].CSC_2100,student[i].CSC_2101,student[i].CSC_2102,student[i].CSC_2103,student[i].CSC_2104);
  66. for (i = 0; i<3;i++)
  67.  
  68.  
  69. bubblesort(array, N);
  70. printf("\n");
  71. for (i =0; i < 3; i++){
  72. printf("%.2f\t",array[i]);
  73. if (array[i]<50)
  74. printf("Sorry try next year");
  75. else
  76. printf("congratulations, you passed!");
  77. printf("\n");
  78. }
  79. return 0;
  80. }
Last edited by Ancient Dragon; Nov 18th, 2007 at 12:25 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,398
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1467
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: A program to print out a word that appears the most number of times

 
0
  #4
Nov 18th, 2007
I suppose you think we are that stupid? That isn't your program because it does not do anything that is required in your assignment that you originally posted. We aren't as dumb as you might think we are.

Trash that entire program and begin a new one. This time we want to see YOUR work, not someone elses.
Last edited by Ancient Dragon; Nov 18th, 2007 at 12:29 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 514
Reputation: Jishnu will become famous soon enough Jishnu will become famous soon enough 
Solved Threads: 26
Jishnu's Avatar
Jishnu Jishnu is offline Offline
Posting Pro

Re: A program to print out a word that appears the most number of times

 
0
  #5
Nov 18th, 2007
What nonsense code have you submitted?! I fully agree with Ancient Dragon.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 24
Reputation: kiel19 is an unknown quantity at this point 
Solved Threads: 0
kiel19 kiel19 is offline Offline
Newbie Poster

Re: A program to print out a word that appears the most number of times

 
0
  #6
Nov 18th, 2007
get serious, the re4maing part of the program is, to print the names, the average and the comment but all arranged in descending order, basing on the average
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 24
Reputation: kiel19 is an unknown quantity at this point 
Solved Threads: 0
kiel19 kiel19 is offline Offline
Newbie Poster

Re: A program to print out a word that appears the most number of times

 
0
  #7
Nov 18th, 2007
teach me how to format my program befor posting
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,398
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1467
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: A program to print out a word that appears the most number of times

 
0
  #8
Nov 18th, 2007
Originally Posted by kiel19 View Post
teach me how to format my program befor posting
Its really simple, just put [code=c] at the top and [/code] at the bottom.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: A program to print out a word that appears the most number of times

 
0
  #9
Nov 18th, 2007
Originally Posted by kiel19 View Post
teach me how to format my program befor posting
Here you go

You might also try the post titled Read Me: Read This Before Posting as well as this announcement
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC