Re: i need help about Turbo C



Manmeet Mittal wrote:
Hi Pipito, This is manmeet Mittal, U can also write the code as follows :-
>> printf("\n Name"); scanf("%s",name);

Bad idea. The %s has no limit to how many characters it will attempt to read and place in the name array. It might overflow the array. This kind of bug is the cause of most of the security issues in programs around the world. It's important to be vigilant and always consider buffer overflow, no matter how simple or trivial the program is.

printf("\n Address"); scanf("%s",address);
printf("\n Age"); scanf("%d",&age);
' \n ' is an escape sequence which causes the output in new line.
>>> In input of age u can use ' & ' ampersand.

If age has type int, then you are right, you need the ampersand to give the address of age, so that scanf can store into your age variable.

U can also write code to input a string as follows :-
puts("\n Name"); gets(name);

NO!!! NEVER USE gets!!!

Didn't I just tell you above, how important it is to consider buffer overflows? The gets function is bad, evil and wrong. It is unsafe, and it cannot be made safe. Do you see why?

One alternative is to use fgets:

fgets(name, sizeof name, stdin);
char *p = strchr(name, '\n');
if(p != NULL) *p = 0;

The two extra lines are to find and remove the newline character from the end of the string, since fgets doesn't do that for you.

I think it will serve your purpose. If u have any query then send ur queris.
Name :-Kumar Gaurav
address :-India
age 19

A man of your age should know better than to use juvenile abbreviations like ‘u’ when talking to adults.

--
Simon.

(for fun, ...)
Name :- Simon Biber
Address :- Sydney Australia
Age :- 23
.



Relevant Pages

  • Re: What Single Universe?
    ... >> Daibhid Ceanaideach wrote: ... >> that with the Silver Age heroes as well. ... > Golden Age characters who have still existed since the 40s had ... nothing but one big soap opera. ...
    (rec.arts.comics.dc.universe)
  • Re: What to do about death when only space gives a limit?
    ... [limited space, food not an issue, not-ageing trick, perfect health, ... choose if and when he wants to age. ... I prefer to have my characters be realistic. ... A child-sized body ...
    (rec.arts.sf.composition)
  • Re: Funny moments from the Silver Age
    ... Yes, I admit it, I wanted one of my favorite characters to be ... some preconceived notion you have about all girls her age. ... Young Amazons, never having met a male, would not run around lovestruck at ... They had nothing to do with Donna Troy ...
    (rec.arts.comics.dc.universe)
  • Re: Can C do it ?
    ... If my program prompts for my name and then my age: ... &age)) the scanf saw the remaining characters. ... EOF is not a character. ... Except on very old operating system that are best forgotten. ...
    (comp.lang.c)
  • Re: user input, getchar, and buffer - For C beginners and those with teaching skills...
    ... If my program prompts for my name and then my age: ... &age)) the scanf saw the remaining characters. ... EOF is not a character. ... Except on very old operating system that are best forgotten. ...
    (comp.lang.c)