how can i write following programm:
• a function which searches a string in a second string and returns the endindex of the first occurence
• a function which includes all occurences of the first string in the second string, which will be replaced by a third string
• a main function which scans the three strings and puts the string out within the replacement
it is not allowed to use more headers than stdio.h , stdlib.h and string.h
i could only start with a code like this, as you can see i couldnt solve any of the three problems. i hope you can help me.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int endIdx(char *string1, char *string2, char *occu)
{
for (int i = 0; i < strlen(string1); i++)
{
for (int j = 0; j < strlen(string1); j++)
{
if (string1[i] == string2[j])
{
printf("occurence string1[%d] is in string2[%d]\n", i, j);
occu[j] = string1[i];
}
}
}
return 0;
}
int main()
{
char string1[20];
char string2[20];
char occu[20];
printf("Type in the first string: ");
scanf("%s", string1);
printf("Type in the second string: ");
scanf("%s", string2);
endIdx(string1, string2, occu);
printf("%s\n", occu);
}