Using traversal by pointer to check whether a string is repeated
- by Bob John
bool repeat_char(char *s, int n);
//R: s is a C-string of at least n non-NUL characters and n > 0
//E: returns true if the first n characters are fully repeated throughout the string s, false
// otherwise.
I'm having trouble implementing this function using traversal by pointer. I was thinking that I could extract the first n characters from s, then use that in a comparison with s, but I'm not sure how I could do that. If I'm traversing through s one character at a time, how can I check that it matches a block of text, such as the first n characters of s?
Thanks!