Upload files to "stringhe"
This commit is contained in:
parent
cbb1494fa5
commit
c3243a252f
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
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;
|
||||||
|
}
|
Loading…
Reference in New Issue