Co' ly' do gi` ma` ba.n pha?i allocate memory cho "a" trong ha`m "nhap()", 
ro^`i free no' o+? ha`m "main()"?
Theo nguye^n ta('c OO thi`  ne^n tra'nh su+. "cho^`ng che'o" data cu?a ca'c 
ha`m, hay classes!

-----------------------------------------------
> Date: Fri, 15 Sep 2006 01:51:49 -0700
> From: [EMAIL PROTECTED]
> To: vietlug-users@lists.sourceforge.net
> Subject: Re: [Vietlug] day la doan text tui dinh gui len
> 
> chao moi nguoi! Minh muon truyen con tro a vao trong ham nhap. Sau do goi ham 
> hien thi de hien thi ra. Van de o day la sau khi ra khoi ham nhap cac gia tri 
> nhap vao bien a ko con nua. Minh da thu chay chuong trinh nay voi dieu kien 
> bien a la public. Nhung bi jo minh muon truyen no qua ham vay minh phai lam 
> thie nao xin moi nguoi chi jao. Minh cam on. Day la doan code cua minh
> #include<stdio.h>
> #include<stdlib.h>
> int* nhap(int *a,int n){
>     a=(int*)malloc(n*sizeof(int));
>     if(a!=NULL)
>     for (int i=0;i<n;i++)
>       {
>           printf("a[%d]=",i);
>           scanf("%d",&a[i]);
> }
>     else
>       printf("\nLoi!!!");
>     return a;
> }
> void HienThi(int * a,int n) {
>   for (int i=0;i<n;i++)
>   printf("  %d",a+i);
> }
> int main(){
>   int n,*a;
>     printf("\nNhap so chieu:");
>     scanf("%d",&n);
>     a=nhap(a,n);
>     HienThi(a,n);
>     free(a);
>     return 0;
> }
> Ngo Trung Nhan <[EMAIL PROTECTED]> wrote:
> http://c-faq.com/stdio/scanfprobs.html
> On 9/14/06, NAHieu wrote:
> > On 9/14/06, G TT wrote:
> > > Vi` "white spaces" ddu+o+.c xem nhu+ "string terminator", ne^n xem ma~:
> > >
> > > #inclue
> > > 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
> -----------------------------------------------
> Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ 
> countries) for 2ยข/min or less.

_________________________________________________________________
Use Messenger to talk to your IM friends, even those on Yahoo!
http://ideas.live.com/programpage.aspx?versionId=7adb59de-a857-45ba-81cc-685ee3e858fe
-------------------------------------------------------------------------
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