219,565pages on
this wiki
Add New Page
Discuss this page0 Share
Programa:         Unidad4Ejercicio12.cpp
Fecha:            01/12/2006
Descripción:      Lee una cadena que contiene un nombre y dos apellidos
                  y los muestra por separado.

#include <iostream>
#include <conio>
#include <stdlib>
#include <ctype>
using namespace std;

int strbusca(char *cad, char c, int p = 0);
void strsubcadena(char *c, char *s, int ini, int lon);

void main()
      char cadena[20], subcadena[20];
      int posIni, lon;

      cout << "Introduzca una cadena ";

      cout << "Introduzca una posicion inicial ";
      cin >> posIni;

      cout << "Introduzca la longitud de la subcadena ";
      cin >> lon;

      strsubcadena(cadena, subcadena, posIni, lon);

      cout << "La subcadena es " << subcadena;


int strbusca(char *cad, char c, int p)
      int i = p,res = -1;
      while(i < strlen(cad) && res == -1)
            if(c == cad[i])
                  res = i;
      return res;

void strsubcadena(char *c, char *s, int ini, int lon)
      int i, j;
      for(i = ini, j = 0; i < ini + lon; i++, j++)
            s[j] = c[i];
      s[j] = '\0';

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random wikia