0

​​​​​I've been trying to make the strcpy function for practice purposes and came across this problem; I wasn't really able to find the problem in this piece of code, but even in the original function it gives an error when trying to copy a string into another string smaller in size.

This is the error:

(43:2: error: stray ‘\342’ in program
{​​​​​
^)***

The code:

#include <iostream>
#include <string>

using namespace std;

void my_strcpy (char s1[], char s2[])
{​​​​​
  int count = 0;
  while (s2[count] != '\0')
  {​​​​​
    s1[count]= s2[count];
    count++;
  }​​​​​
  s1[count] = '\0';
  cout << "the first array after copying is : " << s1 << endl;
  cout << "the second array after copying is : " << s2 << endl;
}​​​​​

int main ()
{​​​​​
  char x[] = "Mah";
  char y[] = "Mahmoud";

  my_strcpy(y, x) << endl;

  cout << "x = " << x << endl;

  cout << "y = " << y << endl;

  return 0;
}
ocrdu
  • 2,057
  • 6
  • 13
  • 21

0 Answers0