6 Replies - 3321 Views - Last Post: 14 October 2018 - 06:07 AM Rate Topic: -----

#1 nachh   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 04-June 18

homework menu

Posted 04 June 2018 - 02:21 PM

Hello I need help with a program at c
The program is to build a menu
You can use pointer functions and strings


1. Write a function that accepts a string (source string) up to 80 and returns only the third word to main. Print the source string wherever you want in main.
Example: Source string - it is nice day. A third nice word will be returned from a function.


2. Write a function that accepts the source string that was entered in section 1 and another string (search string) up to 80 and returns how many times the search string appears in the source string. The two strings are captured from the user. Print the source and search strings and the result (outside of the main function).


Example: source string blalala, string search la. Function will return 3




3. Write a function that accepts the source string and prints a few times each letter (a-z) in a string. If a particular letter does not appear then there is no need to print its number of occurrences. A small and large letter should be treated as the same letter (eg a and A).


1. Write a function that accepts the source string and a positive or negative integer and moves the string elements in this number forward or backward in a cyclic manner. Updating the string. The string must be printed before and after the change (outside the main function). For example - for the string "Hello Dan!" With parameter 2 the result will be "n! Hello Da" and with parameter 4, the result will be "o Dan! Hell"


That's what I've done until now...


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


#define LINE_SIZE 80


void main ()
{
   int count_lett=0;
   char ch,str[LINE_SIZE],chbig;
   char str1[LINE_SIZE]={0};
   int i=0,numofword=0,flag,count=0,j=0;
printf("hello please enter a sentace\n");
   gets(str1);
 while (str1[i]  != '\0') {
       if (str1[i] != ' ')
       {
           if(str1[i-1] == ' '|| i == 0 )
           {
               numofword++;
           }

       }
       if (numofword ==3 )
           break;
       i++;
   }
   flag = i;
   for(flag ; str1[flag] != ' ' && str1[flag] != 0; flag++)
       printf("%c",str1[flag]);
   printf("\n");
   printf("%s\n",str1);
printf("please enter word to search");
   scanf("%s",str);
   for(i=0 ; i<LINE_SIZE ; i++)
   {
       for (j=0 ; j<strlen(str) && str1[i] == str[j] ; j++){
           i++;
           if (str1[i] != str[j])
               count++;
               break;

       }
   }
printf("the word %s apper %d times\n",str,count);






   for(ch=97, chbig=65 ; chbig<=90 && ch<=122 ; ch++, chbig++){
       for(i=0 ; i<LINE_SIZE ; i++){
           if (ch == str1[i] || chbig == str1[i])
               count_lett++;
       }
       if (count_lett > 0){
printf("the leeter |%c/%c| apeer %d times\n",ch,chbig,count_lett);
       }
       count_lett=0 ;
       }

}





Is This A Good Question/Topic? 0
  • +

Replies To: homework menu

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14507
  • View blog
  • Posts: 58,158
  • Joined: 12-June 08

Re: homework menu

Posted 04 June 2018 - 02:35 PM

Do you have a question?
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6508
  • View blog
  • Posts: 22,284
  • Joined: 05-May 12

Re: homework menu

Posted 04 June 2018 - 04:07 PM

Moving to C/C++ forum. The code above is definitely not C# code.
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6508
  • View blog
  • Posts: 22,284
  • Joined: 05-May 12

Re: homework menu

Posted 04 June 2018 - 04:28 PM

I find it interesting that the first sentence says to build a menu, but it make no mention of a menu of what. Considering that this is for a programming class, I would expect the teacher to understand the need for precision in instructions, yet the above seems to lack that.

As for the OP's code, the requirements say that 4 functions be written, but I just see a whole pile of code thrown into the main().
Was This Post Helpful? 0
  • +
  • -

#5 jimblumberg   User is offline

  • member icon

Reputation: 5594
  • View blog
  • Posts: 17,261
  • Joined: 25-December 09

Re: homework menu

Posted 04 June 2018 - 08:54 PM

Also posted here.
Was This Post Helpful? 1
  • +
  • -

#6 vividexstance   User is offline

  • Tiocfaidh ár lá
  • member icon

Reputation: 794
  • View blog
  • Posts: 2,880
  • Joined: 31-December 10

Re: homework menu

Posted 14 October 2018 - 05:11 AM

Why is this a pinned topic?
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6508
  • View blog
  • Posts: 22,284
  • Joined: 05-May 12

Re: homework menu

Posted 14 October 2018 - 06:07 AM

<sarcasm>Probably because our ancient forum software and UI design is so touch friendly.</sarcasm> Very likely I may have fat fingered the pin option.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1