Question

Define a function with the prototype void ocpl(char str[]); that prints each character in the string...

Define a function with the prototype

void ocpl(char str[]);

that prints each character in the string str on a line by itself.

c++

Homework Answers

Answer #1

Program Code Screenshot:

Sample Output:

The screenshots are attached below for reference.

Please follow them for proper output.

Program code to copy:

#include <iostream>
using namespace std;
void ocpl(char str[]);

void ocpl(char str[]){//function definition
int i=0;
while(str[i]!='\0'){//for each character of string
cout<<str[i]<<endl;//print in a newline
i++;
}

}
int main() {
char s[]="string";
ocpl(s);//call function
return 0;
}

Know the answer?
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
Similar Questions
Write a function to create a copy of a string with the prototype below. (C Language)...
Write a function to create a copy of a string with the prototype below. (C Language) char * strcpy (const char *); The function should dynamically allocate the necessary memory for the new string. You can do that with char * newstr = (char *) malloc(sizeof(char) * (strlen(str)+1)); assuming str is your input string. Think though how you would copy the characters of the string, and don't forget about the end of string character.
Use C language    bool isupper(char c): This function returns true if the character in c is...
Use C language    bool isupper(char c): This function returns true if the character in c is an uppercase character between A and Z (inclusive). Note that the C standard library function isupper() both accepts and returns an int, not char or bool, but the behavior is equivalent.     void strlower(char str[]): Change all uppercase ASCII characters in the C string str to their lowercase equivalents. For example, A would become a, and G would become g. All other characters in...
Write a function with the prototype void stars(int i);. The function prints a line of i...
Write a function with the prototype void stars(int i);. The function prints a line of i stars followed by a new line. Write code to apply the stars function to every node in some binary tree called Tree using an in-order traversal, where the number of stars printed is given by the data of the node in the BST. You must write both the function definition and the code that uses it with the star function.
Write a function to find the last occurrence of a string within another string. The function...
Write a function to find the last occurrence of a string within another string. The function should use the prototype below. Use pointer arithmetic when traversing the strings. (C Language) char * search_string(const char * str, const char * substr);
#include #include #define MAX_SIZE 1300 // Maximum string size int main() { char str[MAX_SIZE]; char tosearch[MAX_SIZE];...
#include #include #define MAX_SIZE 1300 // Maximum string size int main() { char str[MAX_SIZE]; char tosearch[MAX_SIZE]; printf("Enter any string: "); gets(str); printf("Enter word to search occurrences: "); gets(tosearch); int cursor = 0; int i = 0; int stringLen = 0; int searchLen = 0; int count1; int count2; stringLen = strlen(str); searchLen = strlen(tosearch); count1 = 0; count2 = 0; for (cursor = 0; cursor <= stringLen; ) { if (str[cursor] == tosearch[i]) { count1++; if (count1 == searchLen) {...
C++: Write a function that receives a pointer to a character string consisting of only alphabets...
C++: Write a function that receives a pointer to a character string consisting of only alphabets a-z and returns the character with the maximum number of repetitions. If more than one-character repeats same number of times, return the character with smallest alphabetical order. For example, the string “Mississippi” has three repeated characters (i-4, s-4, p-2). Both ‘i’ and ‘s’ repeated 4 times but ‘i’ is alphabetically smaller hence the function should return ‘i’. Do not count repeated blanks, special characters,...
int truncate(char str[], unsigned int index); Create a function called truncate() that takes a string and...
int truncate(char str[], unsigned int index); Create a function called truncate() that takes a string and integer as a parameter. Your function should truncate the string by placing a NULL byte at the specified index. You should return the index passed as a parameter if successful, -1 on fail. For example, if the index given is 5, but the string is “fun”, you would return -1 because the string is not long enough.
use c language only to solve this porblem -------------------------- Have the function StringChallenge(str) take the str...
use c language only to solve this porblem -------------------------- Have the function StringChallenge(str) take the str string parameter being passed and return the number of words the string contains (e.g. "Never eat shredded wheat or cake" would return 6). Words will be separated by single spaces. Examples Input: "Hello World" Output: 2 Input: "one 22 three" Output: 3 you have the following code what edits can you do #include <stdio.h> #include <string.h> void StringChallenge(char str[]) {      // code goes...
#include <stdio.h> #define K   1024 /** (2pts) * Copy the string in src to dst. Only...
#include <stdio.h> #define K   1024 /** (2pts) * Copy the string in src to dst. Only copy as many characters (including the * null character) that are in src to dst. Points will be deducted for copying * too many or too few characters. */ void my_strcpy(char dst[], char src[]) { } int main(void) { char input[K+1], copy[K+1]; // Get a line of input (up to K number of bytes) into the 'input' string: // Do not modify any of...
C++ only: Please implement a function that accepts a string parameter as well as two character...
C++ only: Please implement a function that accepts a string parameter as well as two character arguments and a boolean parameter. Your function should return the number of times it finds the character arguments inside the string parameter. When both of the passed character arguments are found in the string parameter, set the boolean argument to true. Otherwise, set that boolean argument to false. Return -1 if the string argument is the empty string. The declaration for this function will...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT