c - How to control the terminal ouput format in linux? -
c - How to control the terminal ouput format in linux? -
my task write little version of ls command. successful read directory , stored names of files sorted array. question how print out them in column format. , how utilize scheme phone call ioctl() help me format?
$ ls file.txt file2.txt file5.txt file8.txt file0.txt file3.txt file6.txt file9.txt file1.txt file4.txt file7.txt
thank much guys!
assuming filenames
array containing c strings filenames , filenames_size
amount of c strings in array.
char **filenames; size_t filenames_size; size_t filenames_len = 0; (size_t = 0; < filenames_size; ++i) { size_t len = strlen(filenames[i]); if (filenames_len < len) { filenames_len = len; } } (size_t = 0; < filenames_size; ++i) { printf("rwxrwxrwx %-*s 10kb\n", filenames_len, filenames[i]); }
printf
can pad string, here. first longest filename, utilize pad rest.
c format ls
Comments
Post a Comment