This program is not \n terminating and keep taking input

35 views Asked by At

This program is not \n terminating and keep taking input until the size of array is specified in condition is not reached.This program should terminate when \n is encounterd.


#include<iostream>
using namespace std;
int main()
{   
    int size = 20;
    char firstName[size];
    char c = '0';       
    int i=0;
    cout<<"Enter Name : ";
            while(c != '\n' && i < size)
            {
                cin>>c;
                cout<<i<<endl;
                firstName[i] = c;
                i++;
            }
            firstName[i-1]='\0';
            cout<<"Output : ";
    puts(firstName);

    return 0;
}

I am expecting that this program take input without any problem and give me output as expected without any hasal.

0

There are 0 answers