Hi, I am currently working on some code that will display all filenames, filesizes and starting inode number for the current directory (although i would like to change it so that the user can input a directory to display. Anyways here is my code...
Code:
#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
#include <string.h>
int main() {
//printf("file i-node example\n");
DIR *currentDirectory;
struct dirent *fileEntry;
struct stat *file_stat;
currentDirectory = opendir(".");
printf("Name\tInode\tSize\n");
if( currentDirectory != NULL ) {
while( ( fileEntry = readdir( currentDirectory ) ) != NULL ) {
printf( "%s\t%d\t%u\n", fileEntry->d_name, fileEntry->d_ino, file_stat->st_size );
}
closedir( currentDirectory );
}
return 1;
}
The issue that I am having is that the filesizes that are given are CRAZY!, here is a copy of the output...
Name Inode Size
test 262624 3506801480
coursework.c~ 265169 3506801480
test2.c 265163 3506801480
test2.c~ 265176 3506801480
coursetest.c 265044 3506801480
.. 262171 3506801480
dir_inode.c~ 265071 3506801480
a.out 262399 3506801480
main.c 262408 3506801480
dir_inode.c 265140 3506801480
. 262217 3506801480
coursework.c 265165 3506801480
test.c~ 265166 3506801480
test.c 265053 3506801480
Thanks for reading :-)
(I feel like it could be a stupid error that I have made as I have been staring at my screen for hours now!)