Compilation error


here i am returing the character to arraya[i] instead of using another chacter(ch) variable then where is the error
pls sort this

#include <iostream>

using namespace std;

int main() {

    char a[100];

    int i=0;

    char ch=cin.get();

    while(ch!='\n'){

        a[i]=ch;

        ch=cin.get();

        i++;

    }

    a[i]='\0';

cout<<a;

}

this is correct way

in your approach you are checking condition a[i]!=’\n’ but a[i] is not assigned any value it contains garbage initially hence give error