Question

Write a function that accepts a pointer to a C-str
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
using namespace std;
int main()
{
char *str;
cout<<"enter a string:";
cin>>str;
noofw(*str);
return 0;
}
int noofw(char *s)
{
char *c;
c=s;
int n=0;
while(c!='\0')
{
if(*c=='w')n++;
c++;
}
return n;
}

Add a comment
Know the answer?
Add Answer to:
Write a function that accepts a pointer to a C-string as its argument. The function should...
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
  • 1. String Length Write a function that returns an integer and accepts a pointer to a...

    1. String Length Write a function that returns an integer and accepts a pointer to a C-string as an argument. The function should count the number of characters in the string and return that number. Demonstrate the function in a simple program that asks the user to input a string, passes it to the function, and then displays the function’s return value. c++

  • Write a program with a function that accepts a string as an argument and returns a...

    Write a program with a function that accepts a string as an argument and returns a copy of the string with the first character of each sentence capitalized. For instance, if the argument is “hello. my name is Joe. what is your name?” the function should return the string “Hello. My name is Joe. What is your name?” The program should let the user enter a string and then pass it to the function. The modified string should be displayed.

  • In C programming. write a function that accepts a string (a pointer character) and deletes all...

    In C programming. write a function that accepts a string (a pointer character) and deletes all the leading spaces.

  • 1. Write a function called ordinal_sum that accepts a string argument and returns the sum of...

    1. Write a function called ordinal_sum that accepts a string argument and returns the sum of the ordinal values of each character in the string. The ordinal value of a character is its numeric Unicode code point in decimal. 2. Write code that creates a Python set containing each unique character in a string named my_string. For example, if the string is 'hello', the set would be {'h', 'e', 'l', 'o'} (in any order). Assign the set to a variable...

  • Write a python function called gen_pattern that accepts a string as an argument. Your function should...

    Write a python function called gen_pattern that accepts a string as an argument. Your function should generate a string pattern based on argument provided: If the string provided is a number and that number is even generate a pattern of hash signs. ex. gen_pattern(‘4’): #### If the string provided is odd, generate pattern of stars. Ex: gen_pattern(3): *** If string is not a number just output “ Not a number”

  • **C** Write a C function that inputs a pointer to a string and a pointer to...

    **C** Write a C function that inputs a pointer to a string and a pointer to a buffer. The function then scans through the string removing leading and trailing whitespace and replacing any run of whitespace within the string with a single space. Your function should follow this prototype: void tighten(char *oldstring, char* newstring, int length); The first argument is a pointer to a null-terminated string sitting somewhere in memory. The second argument is a pointer to the first char...

  • using c++ program write this program without the optional exercise 3. Word Counter Write a function...

    using c++ program write this program without the optional exercise 3. Word Counter Write a function that accepts a pointer to a C-string as an argument and returns the number of words contained in the string. For instance, if the string argument is "Four score and seven years ago” the function should return the number 6. Demonstrate the function in a program that asks the user to input a string and then passes it to the func tion. The number...

  • JAVA Write a method that accepts a String as an argument. The method should use recursion...

    JAVA Write a method that accepts a String as an argument. The method should use recursion to display each individual character in the String. Then, modify the method you just wrote so it displays the String backwards. The following code does not correctly display the String backwards. It merely moves the first character of the String to the end: public static void displayCharacter(String s)    {        if(s.length() == 0)            return;        else       ...

  • write a function which takes a string argument and a character argument. It should return a...

    write a function which takes a string argument and a character argument. It should return a truth value (int 0 or 1), 0 if the string does not contain the character, and 1 if the string does contain the character. Do not use a built-in library for this. Again, call this function and its variables whatever you deem appropriate. The main function of the program should accept a single character followed by Enter. Then, it will read lines until the...

  • To be written in C++ write a recursive function that accepts a string object as its...

    To be written in C++ write a recursive function that accepts a string object as its argument and prints the string in reverse order. demonstrate the function in a driver program.

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