copy x to y without header files string.h
copy array of char to another without strcpy in c++
input : car a car
i want output without space or garbage : caracar
but ouput contain garbage or if i put : y[50]={0} ouput is one ward just output iscar just
i want output without garbage and "caracar"
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int i;
char x[50], y[50] ;
cout << "Enter : ";
scanf_s("%[^\n]", x, sizeof(x));
for (i = 0; x[i] != '\0'; i++)
if ((x[i] >= 'a' && x[i] <= 'z') || (x[i] >= 'A' && x[i] <= 'Z'))
y[i] = x[i];
y[i] = '\0';
cout << y;
}
output: caracar without space or grabage
int j=0. Then use it to track write position.y[j++] = x[i];