Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

What gets() and getch() does in C?

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
Grishan Pradhan
Posts: 21
Joined: 2018-09-30 12:46

What gets() and getch() does in C?

#1 Post by Grishan Pradhan »

In the 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();
}
What gets() and getch() does in this program?
(EDITED)
Last edited by Grishan Pradhan on 2018-10-08 07:38, edited 2 times in total.

User avatar
roseway
Posts: 1528
Joined: 2007-12-31 22:50
Location: Kent, UK
Has thanked: 3 times
Been thanked: 4 times

Re: What gets() and getch() does in C?

#2 Post by roseway »

It waits for you to press any key before the program closes.
Eric

Grishan Pradhan
Posts: 21
Joined: 2018-09-30 12:46

Re: What gets() and getch() does in C?

#3 Post by Grishan Pradhan »

roseway wrote:It waits for you to press any key before the program closes.
Which one?

User avatar
GarryRicketson
Posts: 5644
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: What gets() and getch() does in C?

#4 Post by GarryRicketson »

Well, any key you decide to press.

What gets() and getch() does in C?

Grishan Pradhan
Posts: 21
Joined: 2018-09-30 12:46

Re: What gets() and getch() does in C?

#5 Post by Grishan Pradhan »

Sorry . I there was a mistake on my question.
My question was 'What gets() and getch() does in this program?'
By 'which one?' I meant getch() or gets().

User avatar
GarryRicketson
Posts: 5644
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: What gets() and getch() does in C?

#6 Post by GarryRicketson »

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/getch
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.
Please Read.. What we expect you have already Done.

reinob
Posts: 1189
Joined: 2014-06-30 11:42
Has thanked: 97 times
Been thanked: 47 times

Re: What gets() and getch() does in C?

#7 Post by reinob »

Grishan Pradhan wrote:In the 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();
}
What gets() and getch() does in this program?
(EDITED)
You should do your homework yourself.
And you should learn somewhere else. If your teacher is teaching you that then you should ask for a refund a go somewhere else.

In case you or your teacher haven't been awake in the last 30 years: DOS is not a thing anymore. "conio" was a library from Borland (of "Turbo C" fame) for DOS.

More importantly, drop, forget, kill, delete gets(). Never use it. It's bad, it's wrong and it's insecure. Ask your teacher why!

Good luck.

PS: Oh, and main() returns an int. void main() is actually wrong. Ask your teacher why.

Grishan Pradhan
Posts: 21
Joined: 2018-09-30 12:46

Re: What gets() and getch() does in C?

#8 Post by Grishan Pradhan »

FYI
I don't have any teacher. My class hasn't started yet. I am learning C programming on my own.

Grishan Pradhan
Posts: 21
Joined: 2018-09-30 12:46

Re: What gets() and getch() does in C?

#9 Post by Grishan Pradhan »

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/getch
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.
Please Read.. What we expect you have already Done.
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.

reinob
Posts: 1189
Joined: 2014-06-30 11:42
Has thanked: 97 times
Been thanked: 47 times

Re: What gets() and getch() does in C?

#10 Post by reinob »

Grishan Pradhan wrote:FYI
I don't have any teacher. My class hasn't started yet. I am learning C programming on my own.
Fair enough. Then I'd recommend you to dump your book and get a new one.
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.

Grishan Pradhan
Posts: 21
Joined: 2018-09-30 12:46

Re: What gets() and getch() does in C?

#11 Post by Grishan Pradhan »

reinob wrote:
Grishan Pradhan wrote:FYI
I don't have any teacher. My class hasn't started yet. I am learning C programming on my own.
Fair enough. Then I'd recommend you to dump your book and get a new one.
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.
Thanks Mate!

User avatar
pylkko
Posts: 1802
Joined: 2014-11-06 19:02

Re: What gets() and getch() does in C?

#12 Post by pylkko »

Grishan Pradhan wrote:
roseway wrote:It waits for you to press any key before the program closes.
Which one?
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.

Not only does formulating a question in an unambiguous manner help people understand you, it is a skill that will be helpful in programming.

Grishan Pradhan
Posts: 21
Joined: 2018-09-30 12:46

Re: What gets() and getch() does in C?

#13 Post by Grishan Pradhan »

pylkko wrote:
Grishan Pradhan wrote:
roseway wrote:It waits for you to press any key before the program closes.
Which one?
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.

Not only does formulating a question in an unambiguous manner help people understand you, it is a skill that will be helpful in programming.
You got it wrong mate. Read my other replies.

When Gary answered my question there was a mistake on my question. I had asked about getch() only at that time while I was supposed to ask 'get() and getch()' , later I edited that.

noviceDebian
Posts: 18
Joined: 2018-12-18 02:54

Re: What gets() and getch() does in C?

#14 Post by noviceDebian »

This is the right forum if you have any problems with compilers or IDEs in your Debian installation but not for the kind of questions you are asking.

The kind of questions you are asking are better suited for programming related forums like dreamincode.net or stackexchange.

User avatar
llivv
Posts: 5340
Joined: 2007-02-14 18:10
Location: cold storage

Re: What gets() and getch() does in C?

#15 Post by llivv »

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.
I raise me glass with you tonight!
thank you
In memory of Ian Ashley Murdock (1973 - 2015) founder of the Debian project.

Post Reply