I'm trying to insert a string
into another string
. when I find the first apparition of the user defined character, and inserting the string after the first position of the character and I can't get the program to take ' '
(space) as a character not as a separator.
#include <iostream>
#include <math.h>
#include <fstream>
#include <strings.h>
using namespace std;
int main()
{
int i=0,j=0,ok=0,k=0,p=0;
char s[256],aux[256],a[256];
char c;
cin.get(s,256);//reading the string
cin.get();
cin.getline(a,256);//reading the string that I want to insert
cin.getline();
cin>>c;//reading the separator
strcpy(aux,s);
while(j<=strlen(s) && s[j]!=c)//searching for the first apparition of the separator
{
j++;
}
ok=strlen(a);
strcpy(s+j+1,a);//making room for the string that insert and inserting the string
strcpy(s+j+ok,aux+j);
cout<<s;
}