Announcement

Collapse
No announcement yet.

lỗi ")" expected, ai sửa giúp mình với

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [C++] lỗi ")" expected, ai sửa giúp mình với

    Chào mọi người mình đang code quản lý sinh viên bằng dslk đơn, khi code xong chạy thử thì nó báo lỗi ")" expected, mình tìm mãi không biết nó nằm ở đâu, mong mọi người sử giúp mình.

    PHP Code:
    #include <conio.h>
    #include <stdio.h>
    #include <stdlib.h>

    typedef struct tagSinhVien{
        
    char hoten[30];
        
    char malop[10];
        
    float toan;
        
    float ly;
        
    float hoa;
    }
    SV;

    typedef struct tagNode{
        
    SV info;
        
    struct tagNode *pNext;
    }
    Node;

    typedef struct tagList{
        
    Node *pHead;
        
    Node *pTail;
    }List;

    NodeCreateNode(SV x){
        
    Node *p=(Node *)malloc(sizeof(Node));
        if(
    p==NULL){
            
    printf("\nKhong du bo nho cap phat");
            exit(
    1);
        }
        
    p->info=x;
        
    p->pNext=NULL;
        return 
    p;
    }

    void CreateList(List &l){
        
    l.pHead=NULL;
        
    l.pTail=NULL;
    }

    void AddHead(List &l,Node *p){
        if(
    l.pHead==NULL){
            
    l.pHead=p;
            
    l.pHead=l.pTail;
        }
        else{
            
    p->pNext=l.pHead;
            
    l.pHead=p;
        }
    }

    void PrintList(List l){
        
    Node *p;
        
    printf("\nDanh sach sinh vien:");
        for(
    p=l.pHead;p!=NULL;p=p->pNext){
            
    printf("\nMa lop: %s",p->info.malop);
            
    printf("\nHo ten: %s",p->info.hoten);
            
    printf("\nToan: %f",p->info.toan);
            
    printf("\nLy: %f",p->info.ly);
            
    printf("\nHoa: %f",p->info.hoa);
        }
    }

    void main(){
        
    int n,i;
        
    system("cls");

        
    printf("Nhap so luong sinh vien:");
        
    scanf("%d",&n);
        
    SV x;
        List 
    l;
        
    CreateList(l);
        for(
    i=0;i<n;i++){
            
    printf("\nsinh vien thu %d:",i+1);
            
    printf("\nma lop:");
            
    fflush(stdin);
            
    gets(x.malop);
            
    printf("\nho ten:");
            
    fflush(stdin);
            
    gets(x.hoten);
            
    printf("\ntoan:");
            
    scanf("%f",&x.toan);
            
    printf("\nly:");
            
    scanf("%f",&x.ly);
            
    printf("\nhoa:");
            
    scanf("%f",&x.hoa);
            
    Node *p=CreateNode(x);
            
    AddHead(l,p);
        }
        
    PrintList(l);
        
        
    system("pause");


  • #2
    Bạn xem lại chỗ hàm AddHead đó:
    PHP Code:
    void AddHead(List &l,Node *p){
        if(
    l.pHead==NULL){
            
    l.pHead=p;
            
    l.pHead=l.pTail;   // Sai phải là l.pTail=l.pHead
        
    }
        else{
            
    p->pNext=l.pHead;
            
    l.pHead=p;
        }

    Get link VIP FShare
    http://linhf.com/fshare
    To the world you may be one person, but to one person you may be the world.

    Comment


    • #3
      Originally posted by 11520210 View Post
      Bạn xem lại chỗ hàm AddHead đó:
      PHP Code:
      void AddHead(List &l,Node *p){
          if(
      l.pHead==NULL){
              
      l.pHead=p;
              
      l.pHead=l.pTail;   // Sai phải là l.pTail=l.pHead
          
      }
          else{
              
      p->pNext=l.pHead;
              
      l.pHead=p;
          }

      không được rùi pro ơi, vẫn bị lỗi trên.

      Comment


      • #4
        code của b chạy bằng visual studio 2010 chạy vô tư không thấy báo lỗi. b dùng phiên bản visual nào? thử thêm dấu chấm phẩy vào sau dấu ngoặc kết thúc của những hàm trên hàm main xem.
        Last edited by 11520182; 19-02-2013, 19:48.

        Comment


        • #5
          Originally posted by ruonguit View Post
          không được rùi pro ơi, vẫn bị lỗi trên.
          Code bạn chỉ sai chỗ hàm AddHead đó thui.Mình đã chạy thử bằng VS 2012 rùi.
          Get link VIP FShare
          http://linhf.com/fshare
          To the world you may be one person, but to one person you may be the world.

          Comment


          • #6
            Originally posted by ruonguit View Post
            Chào mọi người mình đang code quản lý sinh viên bằng dslk đơn, khi code xong chạy thử thì nó báo lỗi ")" expected, mình tìm mãi không biết nó nằm ở đâu, mong mọi người sử giúp mình.

            PHP Code:
            #include <conio.h>
            #include <stdio.h>
            #include <stdlib.h>

            typedef struct tagSinhVien{
                
            char hoten[30];
                
            char malop[10];
                
            float toan;
                
            float ly;
                
            float hoa;
            }
            SV;

            typedef struct tagNode{
                
            SV info;
                
            struct tagNode *pNext;
            }
            Node;

            typedef struct tagList{
                
            Node *pHead;
                
            Node *pTail;
            }List;

            NodeCreateNode(SV x){
                
            Node *p=(Node *)malloc(sizeof(Node));
                if(
            p==NULL){
                    
            printf("\nKhong du bo nho cap phat");
                    exit(
            1);
                }
                
            p->info=x;
                
            p->pNext=NULL;
                return 
            p;
            }

            void CreateList(List &l){
                
            l.pHead=NULL;
                
            l.pTail=NULL;
            }

            void AddHead(List &l,Node *p){
                if(
            l.pHead==NULL){
                    
            l.pHead=p;
                    
            l.pHead=l.pTail;
                }
                else{
                    
            p->pNext=l.pHead;
                    
            l.pHead=p;
                }
            }

            void PrintList(List l){
                
            Node *p;
                
            printf("\nDanh sach sinh vien:");
                for(
            p=l.pHead;p!=NULL;p=p->pNext){
                    
            printf("\nMa lop: %s",p->info.malop);
                    
            printf("\nHo ten: %s",p->info.hoten);
                    
            printf("\nToan: %f",p->info.toan);
                    
            printf("\nLy: %f",p->info.ly);
                    
            printf("\nHoa: %f",p->info.hoa);
                }
            }

            void main(){
                
            int n,i;
                
            system("cls");

                
            printf("Nhap so luong sinh vien:");
                
            scanf("%d",&n);
                
            SV x;
                List 
            l;
                
            CreateList(l);
                for(
            i=0;i<n;i++){
                    
            printf("\nsinh vien thu %d:",i+1);
                    
            printf("\nma lop:");
                    
            fflush(stdin);
                    
            gets(x.malop);
                    
            printf("\nho ten:");
                    
            fflush(stdin);
                    
            gets(x.hoten);
                    
            printf("\ntoan:");
                    
            scanf("%f",&x.toan);
                    
            printf("\nly:");
                    
            scanf("%f",&x.ly);
                    
            printf("\nhoa:");
                    
            scanf("%f",&x.hoa);
                    
            Node *p=CreateNode(x);
                    
            AddHead(l,p);
                }
                
            PrintList(l);
                
                
            system("pause");

            Trong thông báo lỗi chắc chắn phải báo luôn lỗi ở dòng nào. Nếu em chưa biết cách đọc thông báo lỗi thì chụp lại màn hình thông báo lỗi rồi đưa lên đây để mọi người xem giúp.

            Comment


            • #7
              mình cảm ơn mọi người rất nhiều, cuối cùng mình sửa được rùi.
              Last edited by ruonguit; 19-02-2013, 22:45.

              Comment


              • #8
                Hồi nãy bạn có hỏi về typedef struct và tại sao lưu .C với .CPP cái bị báo lỗi cái không. Ở trang này có lời giải thích rất rõ. Bạn tìm comment của Adam Rosenfield nhé Do sự khác biệt của cách khai báo struct trong C và CPP.
                http://stackoverflow.com/questions/6...ef-struct-in-c

                P/s: Bạn edit bài làm post của mình không liên quan lắm =.=!
                Last edited by 12520238; 19-02-2013, 22:58.
                Khi ta chào đời, ta khóc mọi người cười
                Sống sao để khi chết đi ta cười còn mọi người khóc.


                Cuộc đời chỉ đáng sống khi còn bạn bè, người thân và quan trọng nhất là ta còn có thể đem lại niềm vui cho người khác

                Comment

                LHQC

                Collapse
                Working...
                X