The problem was described above) The meaning of the program that would find the longest word of 1 line, which should be contained in 2 other lines. All lines are entered by the user. Program Code:

char s1[100], s2[100], s3[100], *ptr=NULL; int n = 0, b = 0, c = 0; int *ch1 = new int[n]; int *ch2 = new int[b]; int *ch3 = new int[c]; char **p1 = new char*[n]; for (int i = 0; i < n; i++) { char *p1 = new char[n]; } char **p2 = new char*[b]; for (int i = 0; i < b; i++) { char *p2 = new char[b]; } char **p3 = new char*[c]; for (int i = 0; i < c; i++) { char *p3 = new char[c]; } cout << "Enter the string: "; gets_s(s1); cout << "Enter the string: "; gets_s(s2); cout << "Enter the string: "; gets_s(s3); ptr = NULL; ptr = strtok(s1, " "); while (ptr != NULL) { p1[n] = ptr; n++; ch1[n] = strlen(ptr); ptr = strtok(NULL, " "); } ptr = NULL; ptr = strtok(s1, " "); while (ptr != NULL) { p2[n] = ptr; n++; ch2[n] = strlen(ptr); ptr = strtok(NULL, " "); } ptr = NULL; ptr = strtok(s1, " "); while (ptr != NULL) { p3[n] = ptr; n++; ch3[n] = strlen(ptr); ptr = strtok(NULL, " "); } checker(n,b,c,p1,p2,p3,Max(ch1)); // Программа проверяет условие задания(Выделяет самое длинное слово и проверяет его на наличие в 2 остальных строках) delete p1, p2, p3, ch1, ch2, ch3; system("pause"); return 0; 
  • And what do you think makes delete p1, p2, p3, ch1, ch2, ch3; ? - AnT

1 answer 1

 int n = 0, b = 0, c = 0; int *ch1 = new int[n]; int *ch2 = new int[b]; int *ch3 = new int[c]; 

This is a selection of arrays of length 0.

It is too

 char **p1 = new char*[n]; for (int i = 0; i < n; i++) { char *p1 = new char[n]; } char **p2 = new char*[b]; for (int i = 0; i < b; i++) { char *p2 = new char[b]; } char **p3 = new char*[c]; for (int i = 0; i < c; i++) { char *p3 = new char[c]; } 

Why did you write these cycles if none of them knowingly fail once?

Nothing can be written to arrays of size zero. You have then suddenly done

 n++; ch1[n] = strlen(ptr); 

those. obvious going beyond the array. Because the program falls.