28 lines
676 B
C++
28 lines
676 B
C++
/*
|
|
AUTORE: Manuel Vichi
|
|
Trova carattere
|
|
*/
|
|
#include <iostream>
|
|
#include <cstring>
|
|
#include <cctype>
|
|
#include <cstdlib>
|
|
using namespace std;
|
|
int charIndex(const char* string, const char character) {
|
|
for (int i = 0; string[i] != '\0'; i++)
|
|
if (string[i] == character)
|
|
return i;
|
|
return -1;
|
|
}
|
|
int main(void){
|
|
char stringa[80+1];
|
|
cout << "Inserisci la stringa: ";
|
|
cin.getline(stringa,sizeof(stringa));
|
|
cout << endl;
|
|
char carattere;
|
|
cout << "Inserisci il carattere: ";
|
|
cin.get(carattere); //modo alternativo per poter leggere lo spazio come carattere
|
|
cout << endl;
|
|
cout << "Indice: " << charIndex(stringa,carattere) << endl;
|
|
return 0;
|
|
}
|