I'm studying for my first midterm and I cam across a review problem that I can't quite figure out.
This is the problem:
Implement the following C++ function that takes a C character string s and a
non-negative integer, returns a character string which is n-copy of s:
char* dup( const char s[], int n ) {
/* if n <=0 , then an empty string is return
Otherwise, a n-copy of s is return .
eg. dup( “hello”,3) returns a string consists of “hellohellohello”
*/
}
I have no clue where to start (or even how to finish)
If you can help, could you explain to me what I should be doing?
1- Implement the following C++ function
2- takes a C character string s
3- a non-negative integer,
4- if non-negative integer ("nni") <1 then error & re-try or exit
5- returns a character string which is n-copy of s:
from #2 " Hello World "
from #3 nni = 3,
from #4 3 > 0 TRUE
from #5 print Hello World Hello World Hello World
The program is straight forward;
accept a small string of chars from the user (#2 & #3)
Checks to confirm that the value is positive, ( ie don't print -7 times ! )
print the string in a loop
stop