Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Exercices S5] Est-ce que les réponses "positives" du QCM doivent refléter un code correct? #8

Open
qdeconinck opened this issue Jan 30, 2020 · 0 comments

Comments

@qdeconinck
Copy link
Collaborator

Dans le QCM S5, la réponse positive pour le comptage des fichiers est la suivante:

int nfiles(char * name) {

           DIR *dirp;
           struct dirent *dp;
           dp=malloc(sizeof(struct dirent));
           if(dp==NULL) {
             return -1;
           }
           dirp = opendir(name);
           if(dirp==NULL) {
             return -1;
           }
           int count=0;
           while ((dp = readdir(dirp)) != NULL) {
              if (dp->d_type==DT_REG) {
                count++;
              }
           }
           int err = closedir(dirp);
           if(err<0) {
              return -1;
           }
           return(count);
         }

Bien que correct, ce programme leak de la mémoire (malloc de dp)... Laisse-t-on cela comme ça?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant