sukanya
BAN USER#include <stdio.h>
int main()
{
char *str = "helloworld";
char *substr = "owo";
int substr_len = 0;
int i = 0, j = 0, count = 0;
for(i = 0; substr[i] != '\0'; i++)
substr_len++;
for(i = 0; str[i] != '\0'; i++) {
for (j = 0; substr[j] != '\0'; j++) {
if (str[i+j] == substr[j])
count++;
}
if (count == substr_len) {
printf("%s\n", str+i);
return 0;
}
count = 0;
}
return -1;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *str1 = "Helloworld";
char *str2 = "llo";
char *temp = (char *)malloc(sizeof(char) * 100);
memset(temp, 0, 100);
int i = 0, j = 0, count = 0, str2_len = 0;
for(i = 0; str2[i] != '\0'; i++) {
str2_len++;
}
for(i = 0; str1[i] != '\0'; i++) {
for(j = 0; str2[j]!='\0'; j++) {
if (str2[j] == str1[i+j]) {
count++;
} else {
break;
}
}
if (str2_len == count) {
for(int k = 0; str1[k]!='\0'; k++) {
if( k < i) {
temp[k] = str1[k];
} else if (!((k > i) && (k < j))) {
temp[k] = str1[k+j];
}
}
printf("%s\n",temp);
return 0;
}
count = 0;
}
return -1;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *str1 = "Helloworld";
char *str2 = "llo";
char *temp = (char *)malloc(sizeof(char) * 100);
memset(temp, 0, 100);
int i = 0, j = 0, count = 0, str2_len = 0;
for(i = 0; str2[i] != '\0'; i++) {
str2_len++;
}
for(i = 0; str1[i] != '\0'; i++) {
for(j = 0; str2[j]!='\0'; j++) {
if (str2[j] == str1[i+j]) {
count++;
} else {
break;
}
}
if (str2_len == count) {
for(int k = 0; str1[k]!='\0'; k++) {
if( k < i) {
temp[k] = str1[k];
} else if (!((k > i) && (k < j))) {
temp[k] = str1[k+j];
}
}
printf("%s\n",temp);
return 0;
}
count = 0;
}
return -1;
}
- sukanya January 03, 2021