conio.h & stdio.h

Write a program to read in the user’s name. User can type a maximum of 25 characters including spaces.
When user ends the entry with <enter> key, or the maximum input limit(25) is reached the name entered is displayed.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>
#include <conio.h>


void main(void)
{
char input;
int j;
j=0;
do
{

	input = _getche();
	if(input = '\n')
	{break;}
	j++;
}while( j<25 && input !='\n');
putchar(input);
}


I can't seem to get this right i'm not sure what im doing wrong.. (this is an assignment)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

int main()
{
    const std::size_t INPUT_LIMIT = 26 ; // 25 characters plus the null character
    char name[INPUT_LIMIT] ;

    std::cout << "name: " ;

    // http://www.cplusplus.com/reference/istream/istream/getline/
    std::cin.getline( name, INPUT_LIMIT ) ;

    std::cout << name << '\n' ;
}
Topic archived. No new replies allowed.