School-Coding-Cpp/sfusi/strchr().cpp

44 lines
620 B
C++

/*
Nome: Mario
Cognome: Montanari
strchr()
*/
#include <iostream>
#include <cstring>
#define SIZE 100+1
using namespace std;
char *strchr(const char *src, int c);
int main(void) {
char src[SIZE];
char *ptr;
int chr = 'a';
cout << "Inserisci una parola o una frase: ";
cin.getline(src, SIZE);
ptr = strchr(src, chr);
if (ptr != nullptr) {
cout << ptr << endl;
} else {
cout << "Character not found!" << endl;
}
return 0;
}
char *strchr(const char *src, int c) {
do {
if (*src == c) {
return (char*)src;
}
} while (*src++);
return NULL;
}