I am doing an assignment that requires me to create a function similar to ls. My code works fine but when it comes to implementing the behaviour of
ls -l child //where child is a folder
there is a weird behaviour.
Let's say i am in the folder 'parent' and in it i have a subfolder, 'child' which contains some text files. When i run my program from the parent folder, it finds the folder and prints out the attributes of the text files in it. However, it will only print the files in the child folder only if the same files itself exists in the parent folder.
Here is a snippet of the code that i am using,
char CurrDir[100];
DIR *pDir = NULL;
struct dirent *pFileNames = NULL;
getcwd(CurrDir, sizeof(CurrDir))
strncat(CurrDir, "/", strlen(CurrDir));
unsigned int CurrDirLen = strlen(CurrDir);
unsigned int CombSize = CurrDirLen + strlen(argv[1]);
char SuperCharArr[CombSize];
for(int i = 0; i < CombSize; ++i)
{
if( i < strlen(CurrDir) )
SuperCharArr[i] = CurrDir[i];
else
SuperCharArr[i] = argv[1][i%CurrDirLen];
}//for
//insert null character at the end of the character
SuperCharArr[CombSize] = '\0';
pDir = opendir( SuperCharArr );
printf("%s\n", SuperCharArr);
if( pDir != NULL )
{
//Directory detected as pDir is a DirectoryStream
printf("%s\n", "pDir not null");
PrintHeader();
while( (pFileNames = readdir(pDir)) != NULL )
{
PrintFileDeails(pFileNames);
}
}//if