Re: i need help about Turbo C
- From: Simon Biber <news@xxxxxxxxx>
- Date: Mon, 17 Jul 2006 18:46:55 GMT
sarathy wrote:
use
scanf ("%[^\n]",name);
scanf ("%[^\n]",address);
Now your name and address can contain any number of spaces..
%[^\n] is good advice, but you should also include a number to limit the number of characters it will attempt to read and put in the array.
Otherwise if the user inputs a line that is too long, it will overflow the array and cause undefined behaviour - something bad might happen.
For example:
char name[128];
scanf("%127[^\n]", name);
Note how the number is one less than the size of the array, to allow for the null character to be stored.
--
Simon.
.
- References:
- i need help about Turbo C
- From: pipito
- Re: i need help about Turbo C
- From: sarathy
- i need help about Turbo C
- Prev by Date: Re: How to write a small graceful gcd function?
- Next by Date: Re: i need help about Turbo C
- Previous by thread: Re: i need help about Turbo C
- Next by thread: Re: i need help about Turbo C
- Index(es):
Relevant Pages
|