+ 2

Error " invalid conversion from ‘char’ to ‘const char*’ " in C++. (SOLVED)

Hello, I have this code that gives me the error from the title: This is problem announcement: Given two strings and a number of successive characters "n" (large enough) from s2 to look for in s, to check if s2 is a plagiarism of s. The s string is: "HILAR". #include <iostream> #include <cstring> #include <string.h> using namespace std; int main() { char s[50], s2[50], s3[50]; int n, nrp, i; bool p; cin.getline(s, 50); cin.getline(s2, 50); cin >> n; p = false; nrp = 0; char *pp = strtok(s, ""); while (pp != NULL) pp = strtok(NULL, ""); nrp = nrp + 1; i = 1; while (i <= nrp && p == false){ strcpy(s3, pp[i]); if (strncmp (s, s3, n) != 0){ p = true; } i = i + 1; } cout << p; return 0; } https://code.sololearn.com/cKQ4yf8jw5H4/#cpp I have updated the version: Test cases: 1) Input: s = "hilar" s2 = "hila" n = 4 Output: p = 1 (TRUE) is plagiarsim. 2) Input: s = "hilar" s2 = "ir" n = 2 Output: p = 0 (FALSE) is not plagiarsim. PROBLEM SOLVED Someone can explain me how to solve this error. Thank you very much.

11th May 2020, 2:23 PM
Joita Vladut
Joita Vladut - avatar
8 Antworten
0
This way works: while (i <= nrp && p == false){ strcpy(s3, s2); if (strncmp (s, s3, n) == 0){ p = true; }
11th May 2020, 8:34 PM
Jayakrishna 🇮🇳
+ 2
At first glance, what is the value for string s there?. You are not taking any input..
11th May 2020, 4:21 PM
Jayakrishna 🇮🇳
+ 2
strcpy copies a string from source to destination. See the link http://www.cplusplus.com/reference/cstring/strcpy/ So, here, source must be is of type not modifiable.. pp[i] not works... What inputs your trying..? Give an example, what you trying...?
11th May 2020, 6:42 PM
Jayakrishna 🇮🇳
+ 1
Sorry for bad posting, i have made a few mistakes there but i modified the code and, i put the link to code there. And this the problem with data: Given two strings and a number of successive characters "n" (large enough) from s2 to look for in s, to check if s2 is a plagiarism of s. The s string is: "HILAR". Thank you for answers.
11th May 2020, 4:45 PM
Joita Vladut
Joita Vladut - avatar
0
s - "hilar" s2 - "hi" n - "2" These are my input values.
11th May 2020, 7:44 PM
Joita Vladut
Joita Vladut - avatar
0
Now works. Thanks
12th May 2020, 7:26 AM
Joita Vladut
Joita Vladut - avatar
0
I have updated the version: Test cases: 1) Input: s = "hilar" s2 = "hila" n = 4 Output: p = 1 (TRUE) is plagiarsim. 2) Input: s = "hilar" s2 = "ir" n = 2 Output: p = 0 (FALSE) is not plagiarsim.
12th May 2020, 7:52 AM
Joita Vladut
Joita Vladut - avatar