#include <stdio.h> #include <conio.h> #include <string.h> int main(int argc, char* argv[]) { char str[100]; char substr[50]; int i; printf("Vvedi stroku:"); gets(str); printf("Vvedi podstroku:"); gets(substr); char* p; p=strstr(str, substr); printf("Pozicii vhozhdeniya: %s\n", p); i=0; while (p=strstr(p,substr)) { i++; p++; } printf("Vsego Vhozhdenii: %d\n", i); _getch(); return 0; }
It is necessary that the program prints the positions of the occurrence of the second line in the first and their total number. My program considers the occurrence of only 2 identical lines and does not determine the position of the occurrence. Tell me, please, how can this be fixed?
man strstr
and if something remains unclear, go back to the chapter on pointers and address arithmetic in the C (or C ++) book. - avp