2020-09-10 10:48:09 +02:00

39 lines
876 B
C
Executable File

/**
* @ Author: JunkJumper
* @ Link: https://github.com/JunkJumper
* @ Copyright: Creative Common 4.0 (CC BY 4.0)
* @ Create Time: 04-09-2020 11:43:11
* @ Modified by: JunkJumper
* @ Modified time: 10-09-2020 10:47:45
* @ Description: code c produisant le même résultat qu'un ls.
*/
/// M311 - myls
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
DIR *dir;
struct dirent *entry;
if (argc != 2)
{
fprintf(stderr, "Syntaxe : %s {le chemin}\n\n", argv[0]);
exit(1);
}
dir = opendir(argv[1]);
entry = readdir(dir);
printf("%-10s %-5s %-30s\n", "Inode", "Type", "Nom de Fichier");
while(entry != NULL) {
printf("%-10d %-5d %-30s\n", (int)entry->d_ino, entry->d_type, entry->d_name);
entry = readdir(dir);
}
closedir(dir);
return 0;
}