Visualizzazione dei risultati da 1 a 9 su 9

Discussione: problema link list C

Visualizzazione discussione

  1. #3
    io sto faccendo cosi ma non so cosa sbaglio come output mi da tutti dati uguali grazie mille
    ho creato questa funzione per inserimento

    struct student* tempNextPoint = NULL; ho creato questo puntatore globale e inizializzo null

    codice:
    void insertDataIntolinkList(char *stufirstname,char *stulastname,int stuage, int sturollno, char *stuclasssection, int stutotalnumber, char *stupromotion){
        struct student* tempStudentInfo = (struct student*)malloc(sizeof(student));
        
        strcpy((*tempStudentInfo).studentFirstName,stufirstname);
        strcpy((*tempStudentInfo).studentLastName,stulastname);
        (*tempStudentInfo).studentAge = stuage;
        (*tempStudentInfo).studentRollNo = sturollno;
        strcpy((*tempStudentInfo).studentClassSection,stuclasssection);
        (*tempStudentInfo).studentTotalNumber = stutotalnumber;
        strcpy((*tempStudentInfo).studentPromotion,stupromotion);
    
    
        (*tempStudentInfo).nextPoint = tempNextPoint;
        tempNextPoint = tempStudentInfo;
    }
    e con questa funzione faccio print di tutti dati ma in output sono tutti uguali anche se inserisco dati diversi perchè
    codice:
    void displayAllStudentResult(){
        struct student* tempPrintPoint = tempNextPoint;
        while(tempPrintPoint != NULL){
            printf("\t\t\n student first name is %s ",(*tempPrintPoint).studentFirstName);
            printf("\t\t\n student last name is %s ",(*tempPrintPoint).studentLastName);
            printf("\t\t\n student age is %d ",(*tempPrintPoint).studentAge);
            printf("\t\t\n student roll number is %d ",(*tempPrintPoint).studentRollNo);
            printf("\t\t\n student class section is %c ",(*tempPrintPoint).studentClassSection);
            printf("\t\t\n student total number %d ",(*tempPrintPoint).studentTotalNumber);
            printf("\t\t\n student promotion %s ",(*tempPrintPoint).studentPromotion);
    
    
            tempPrintPoint = (*tempPrintPoint).nextPoint;
        }
    
    
        printf("\n");
    }
    nel main sto faccendo in questo modo
    codice:
    int studentNumber,num;
        struct student *getStudentInfo;
    
    
        getStudentInfo = (struct student*)malloc(sizeof(struct student));
    
    
        printf("\t\t\n quanti studenti -> ");
        scanf("%d",&studentNumber);
    
    
        for(num = 1; num <= studentNumber; num++ ){
    
    
        printf("\t\t\n enter student firstname (max 40 charecters ) ");
        scanf("%s",&(getStudentInfo)->studentFirstName);
    
    
        printf("\t\t\n enter student lastname (max 40 charecters ) ");
        scanf("%s",&(getStudentInfo)->studentLastName);
    
    
        printf("\t\t\n enter student age ");
        scanf("%d",&(getStudentInfo)->studentAge);
    
    
        printf("\t\t\n enter student roll number ");
        scanf("%d",&(getStudentInfo)->studentRollNo);
    
    
        printf("\t\t\n enter student class section (A,B,C,D ecc... ) ");
        scanf("%s",&(getStudentInfo)->studentClassSection);
    
    
        printf("\t\t\n enter student total number ");
        scanf("%d",&(getStudentInfo)->studentTotalNumber);
    
    
        printf("\t\t\n enter student promotion result  (pass or fail) ");
        scanf("%s",&(getStudentInfo)->studentPromotion);
    
    
        }
    
    
        insertDataIntolinkList((*getStudentInfo).studentFirstName,(*getStudentInfo).studentLastName,(*getStudentInfo).studentAge,(*getStudentInfo).studentRollNo,(*getStudentInfo).studentClassSection,(*getStudentInfo).studentTotalNumber,(*getStudentInfo).studentPromotion);
    
    
        for(num=0;num<=studentNumber;num++){
            displayAllStudentResult();
        }
    
    
        free(getStudentInfo);
    Ultima modifica di shivi_php; 06-10-2013 a 11:38
    shiviphpdevelopment

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.