#include <iostream>
#include <string.h>
using namespace std;
#define MAX 300
int myStrlen(char s[], int k);
void myStrcpy(char s[], int vt, char s1[], int k);
void mySubstr(char s[], int b, int count, char ss[]);
bool myStrcat(char s1[], char s2[]);
void ChenChuoiTaiVitriK(char s[], char s1[], int k);
int main()
{
char s[MAX], s1[MAX];
gets(s);
gets(s1);
int k;
cin >> k;
if (k < 0 || k>myStrlen(s, 0))
cout << "Vi tri " << k << " khong thoa dieu kien." << endl;
else
{
ChenChuoiTaiVitriK(s, s1, k);
cout<<s;
return 0;
}
}
int myStrlen(char s[], int k)
{
int len=0;
while (*s!=NULL)
{
len++;
s++;
}
return len;
}
void mySubstr(char s[], int b, int count, char ss[])
{
int j=0;
int n1=myStrlen(s, 0);
for(int i=b; i<n1 ; i++) {ss[j]=s[i]; j++;}
}
void myStrcpy(char s[], int vt, char s1[], int k)
{
int j=0;
int n1=myStrlen(s,0),n2=myStrlen(s1,0);
for(int i=vt; ;i++)
{
s[i]=s1[j];
j++;
if (s[i]=='\0') break;
}
}
void xoa (char s[MAX],char s1[MAX],int vitrixoa)
{
int n1=myStrlen(s,0),n2=myStrlen(s1,0);
for (int i=vitrixoa;i<n1+n2+1;i++)
{
s[i]=s[i+1];
s[n1+n2]='\0';
}
}
void ChenChuoiTaiVitriK(char s[], char s1[], int k)
{
char ss[10000];
int n1=myStrlen(s,0),n2=myStrlen(s1,0);
int m=k+n2+1;
mySubstr(s, k , 0, ss);
int n3=myStrlen(ss, 0);
myStrcpy(s, k, s1, n2);
s[n1+n2+1]='\0';
s[k+n2]=' ';
myStrcpy(s,m, ss, n3);
for (int i=0;i<n1+n2+1;i++)
{
if (s[i]==' '&&s[i+1]==' ')
{
xoa(s,s1,i);
i--;
}
}
if (s[0]==' ')
{
xoa(s,s1,0);
}
if (s[n1-1]==' ')
{
xoa (s,s1,(n1+n2));
}
}
\ In ra màn hình
An hoc toan.
Nguyen
3
An Nguyen hoc toan.
Process returned 0 (0x0) execution time : 13.363 s
Press any key to continue.
Mọi người có thể giúp em chữa lỗi chỗ kí tự lạ khi xuất ra được ko ạ? em fix mãi mà ko được ạ.