There is nothing ready but (see below) it is not difficult to create a function that does this. If I understood what you wanted, it would be this:
#include <stdio.h>
#include <string.h>
int contem(char s1[], char s2[]) {
int j;
for (int i = 0; s2[i]; i++) {
for (j = 0; s1[j]; j++) {
if(s2[i] == s1[j]) {
break;
}
}
if (s1[j] == '#include <stdio.h>
#include <string.h>
int main() {
char s[] = "abc";
char v[] = "cdeabf";
printf("'%s' %scontém todos os caracteres presentes em '%s'", v, (strspn(s, v) == strlen(s)) ? "" : "não ", s);
return 0;
}
') {
return 0;
}
}
return 1;
}
int main() {
char s[] = "abc";
char v[] = "cdeabf";
if(contem(v, s)) {
printf("'%s' contém todos os caracteres presentes em '%s'", v, s);
} else {
printf("'%s' não contém todos os caracteres presentes em '%s'", v, s);
}
return 0;
}
See working on ideone .
Here's the solution for anyone who wants to do it. But there is a way to achieve the same result as the JJao's response. The function strspn
returns the size of the string being compared if all the characters are present in the other string . So it is easy to identify what is asked in the question. Using ready-made function would look like this:
#include <stdio.h>
#include <string.h>
int contem(char s1[], char s2[]) {
int j;
for (int i = 0; s2[i]; i++) {
for (j = 0; s1[j]; j++) {
if(s2[i] == s1[j]) {
break;
}
}
if (s1[j] == '#include <stdio.h>
#include <string.h>
int main() {
char s[] = "abc";
char v[] = "cdeabf";
printf("'%s' %scontém todos os caracteres presentes em '%s'", v, (strspn(s, v) == strlen(s)) ? "" : "não ", s);
return 0;
}
') {
return 0;
}
}
return 1;
}
int main() {
char s[] = "abc";
char v[] = "cdeabf";
if(contem(v, s)) {
printf("'%s' contém todos os caracteres presentes em '%s'", v, s);
} else {
printf("'%s' não contém todos os caracteres presentes em '%s'", v, s);
}
return 0;
}
See working on ideone .