Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

#include <stdio.

h>
#define MAXCHAR 50

char *findFirst(char *p, char a) {


char *res;
for(int i = 0; i < MAXCHAR; i++) {
while(*(p + i) != '\0') {
if(*(p + i) == a) {
res = p;
} else {
res = NULL;
}
}
}
return res;
}

int main() {
char text[MAXCHAR];
char a, *p;

printf("Enter text > ");


fgets(text, MAXCHAR, stdin);

printf("Enter character > ");


scanf("%c", &a);

p = findFirst(&text[0], a);
if(p == NULL) {
printf("Character %c is not found\n", a);
} else {
printf("%s\n", p);
}

return 0;
}

You might also like