Code: Select all
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
char str[40];
printf("Enter your name:");
gets(str);
puts(str);
getch();
}
(EDITED)
Code: Select all
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
char str[40];
printf("Enter your name:");
gets(str);
puts(str);
getch();
}
Which one?roseway wrote:It waits for you to press any key before the program closes.
===========The C library function char *gets(char *str) reads a line from stdin and stores it into the string pointed to by str. It stops when either the newline character is read or when the end-of-file is reached, whichever comes first.
Please Read.. What we expect you have already Done.getch in C
getch in C language: getch function prompts a user to press a character and that character isn't printed on screen, getch header file is conio.h. This function is not a part of standard C library.
You should do your homework yourself.Grishan Pradhan wrote:In the program:-
What gets() and getch() does in this program?Code: Select all
#include<stdio.h> #include<conio.h> void main(void) { clrscr(); char str[40]; printf("Enter your name:"); gets(str); puts(str); getch(); }
(EDITED)
Yes , I did what you have expected before I came here but I didn't understand the answers that I found on the internet, I checked tutorialspoint too. But no I didn't get that either. So I came here if I could get the answer that I(beginner) could understand.GarryRicketson wrote:You really need to at least try doing some searches before asking these kind of questions,
https://www.tutorialspoint.com/c_standa ... n_gets.htm===========The C library function char *gets(char *str) reads a line from stdin and stores it into the string pointed to by str. It stops when either the newline character is read or when the end-of-file is reached, whichever comes first.
https://www.programmingsimplified.com/c/conio.h/getchPlease Read.. What we expect you have already Done.getch in C
getch in C language: getch function prompts a user to press a character and that character isn't printed on screen, getch header file is conio.h. This function is not a part of standard C library.
Fair enough. Then I'd recommend you to dump your book and get a new one.Grishan Pradhan wrote:FYI
I don't have any teacher. My class hasn't started yet. I am learning C programming on my own.
Thanks Mate!reinob wrote:Fair enough. Then I'd recommend you to dump your book and get a new one.Grishan Pradhan wrote:FYI
I don't have any teacher. My class hasn't started yet. I am learning C programming on my own.
This: https://en.wikipedia.org/wiki/The_C_Pro ... g_Language is still fine to learn C.
(I think it's even freely available online).
gets() is part of the C standard -- but deprecated -- even the manual page says "Never use this function."
It gets a line from the keyboard (stdin) and saves it at the address pointed by the input argument.
It's highly insecure because it will read and store characters until a carriage return/line feed (or end-of-file marker) is received, regardless of how much storage is reserved at the destination address.
getch() was a Borland-specific function for DOS. It reads a single character, without echoing it on screen (thus suitable e.g. for inputting a password).
Cheers.
Just an idea. But if you want to learn programming, then it might be helpful to analyse questions and propositions and attempt to communicate in a unambiguous way. Here when you asked "which one", from the point of view of the reader, it could have referred to a) the pressed key (as Gary assumed), b) the function or possibly c) a program.Grishan Pradhan wrote:Which one?roseway wrote:It waits for you to press any key before the program closes.
You got it wrong mate. Read my other replies.pylkko wrote:Just an idea. But if you want to learn programming, then it might be helpful to analyse questions and propositions and attempt to communicate in a unambiguous way. Here when you asked "which one", from the point of view of the reader, it could have referred to a) the pressed key (as Gary assumed), b) the function or possibly c) a program.Grishan Pradhan wrote:Which one?roseway wrote:It waits for you to press any key before the program closes.
Not only does formulating a question in an unambiguous manner help people understand you, it is a skill that will be helpful in programming.
I raise me glass with you tonight!reinob wrote: gets() is part of the C standard -- but deprecated -- even the manual page says "Never use this function."
It gets a line from the keyboard (stdin) and saves it at the address pointed by the input argument.
It's highly insecure because it will read and store characters until a carriage return/line feed (or end-of-file marker) is received, regardless of how much storage is reserved at the destination address.
getch() was a Borland-specific function for DOS. It reads a single character, without echoing it on screen (thus suitable e.g. for inputting a password).
Cheers.