-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractica.cpp
More file actions
50 lines (49 loc) · 1.12 KB
/
Copy pathpractica.cpp
File metadata and controls
50 lines (49 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
using namespace std;
void inicializarArreglo(int arreglo[], int t, int valor)
{
for (int i = 0; i < t; i++)
{
arreglo[i] = valor;
}
}
int buscarCaracter(char cadena[], char letra, int posiciones[])
{
int cont = 0;
for (int i = 0; cadena[i] != '\0'; i++)
{
if (cadena[i] == letra)
{
posiciones[cont] = i;
cont++;
}
}
return cont;
}
void imprimirResultados(int posiciones[], int t)
{
cout << "Se encontro " << t << " veces" << endl;
for (int i = 0; i < t; i++)
{
cout << posiciones[i] << '\t';
}
cout << endl;
}
void cambiarcaracter(char cadena[],int posiciones[], char letra){
for (int i = 0; posiciones[i] !=-1; i++)
{
cadena[posiciones[i]]=letra;
}
}
int main()
{
const int TAM = 30;
char cadena[TAM] = "Holaaaaaa";
int posiciones[TAM];
inicializarArreglo(posiciones, TAM, -1);
int cantVeces = buscarCaracter(cadena, 'a', posiciones);
imprimirResultados(posiciones, cantVeces);
cambiarcaracter(cadena,posiciones,'x');
cout<< cadena <<endl;
return 0;
}