That was an attempt to answer to the following original question.
Are there some more "experts" on the field?
 
"Mình vừa gặp phải một lỗi rất khó hiểu. Đây là đoạn
mã nguồn của mình:
#include "stdio.h"
 
int main()
{
   char str[80];
     printf("Enter some words: ");
     scanf("%s", str);
     printf("The first word you entered is : %s\n", str );
 
     printf("Enter some words: ");
     scanf("%s", str);
     printf("The first word you entered is : %s\n", str );
 
   return 0;
}
và đây là kết quả mà mình mong đợi:
"Enter some words:hello word
 The first word you entered is:hello
 Enter some words:who are u?
 The first word you entered is:who"
nhưng kết quả mà mình thu được lại là:
"Enter some words: hello word
 The first word you entered is : hello
 Enter some words: The first word you entered is : word"
Không thể hiểu nổi tại sao hàm scanf() lại chỉ hoạt động
đúng một lần. Ngay cả khi mình đã sử dụng hàm fflush(stdin)
nhưng kết quả vẫn như cũ. Ai đó giúp mình với. Mình xin
cám ơn!!!"
---------------------------------------
> Date: Thu, 14 Sep 2006 14:36:26 +0200
> From: [EMAIL PROTECTED]
> To: vietlug-users@lists.sourceforge.net
> Subject: Re: [Vietlug] day la doan text tui dinh gui len
> 
> http://c-faq.com/stdio/scanfprobs.html
> 
> On 9/14/06, NAHieu <[EMAIL PROTECTED]> wrote:
> > On 9/14/06, G TT <[EMAIL PROTECTED]> wrote:
> > > Vi` "white spaces" ddu+o+.c xem nhu+ "string terminator", ne^n xem ma~:
> > >
> > > #inclue <stdio.h>
> > > int main()
> > > {
> > > char str[80];
> > > printf("Enter some words (or 'ctrl-c' to break): ");
> > > scanf("%s", str);  <====== buffer length unchecked HERE
> >
> > It is a very *stupid* idea to use scanf() to get input!
> > fgets() is certainly a better choice in this case.
> > RTFM!
> >
> >
> > Cheers,
> > H
> >
> > -------------------------------------------------------------------------
> > Using Tomcat but need to do more? Need to support web services, security?
> > Get stuff done quickly with pre-integrated technology to make your job 
> > easier
> > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> > _______________________________________________
> > VietLUG-users mailing list
> > VietLUG-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/vietlug-users
> >
> 
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> VietLUG-users mailing list
> VietLUG-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/vietlug-users

_________________________________________________________________
Express yourself with gadgets on Windows Live Spaces
http://discoverspaces.live.com?source=hmtag1&loc=us
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
VietLUG-users mailing list
VietLUG-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vietlug-users

Trả lời cho