ls simulation

    0

    0

    Giovanny Gongora

    Codiga's C Recipes

    Simulate the ls command

    #include <stdio.h>
    #include <dirent.h>
    
    int ls() {
    	struct dirent **namelist;
    	int n, i;
    	char pathname[100];
    	getcwd(pathname);
    	n = scandir(pathname, &namelist, 0, alphasort);
    	if (n < 0) {
    		perror("scandir");
    	}
    	else {
    		for (i = 0; i < n; i++) {
    			if (namelist[i]->d_name[0] != '.') {
    				printf("%s \n", namelist[i]->d_name);
    			}
    		}
    	}
    	printf("\n");
    	return 0;
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.