i have function to search substrings in text:
int text_searcher() { if (local_text == NULL || user_input == NULL) { return -1; }
Coordinates coords[256];
int numMatches = 0;
for (int i = 0; i < local_text_rows && i < sizeof(local_text) / sizeof(local_text[0]); i++) {
if (local_text[i] == NULL) {
continue;
}
char* found = strstr(local_text[i], user_input);
while (found != NULL) {
coords[numMatches].line = i;
coords[numMatches].index = found - local_text[i];
numMatches++;
if (found + 1 < local_text[i] + strlen(local_text[i])) {
found = strstr(found + 1, user_input);
}
else {
break;
}
}
}
printf("Coordinates of the found substrings:n");
for (int i = 0; i < numMatches; i++) {
printf("(%d, %d)n", coords[i].line, coords[i].index);
}
return numMatches;
}
also i have text to search:
Understand the basics of procedural and structural programming by having hands-on experience in using these paradigms. Learn how the memory management works inside the process, understand the virtual memory concept and typical issues with memory allocation and deallocation, learn the basic data types.
and here is substring:
ural
at first time it correctly finds 0 31 coordinates, but then at line
if (found + 1 < local_text[i] + strlen(local_text[i])) { found = strstr(found + 1, user_input); }
found 0x00000000451c435f char *
char
Exception thrown at 0x00007FFA58E52D5D (vcruntime140d.dll) in Assignment1.exe: 0xC0000005: Access violation reading location 0x00000000451C4360.
I expect to get an array of coordinates to print all substring occurrence but instead found + 1 pointer return exception
1