#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct treenode {
char filename[256];
struct treenode* leftchild;
struct treenode* rightchild;
};
typedef struct treenode TreeNode;
/*
This function returns the index of the last occurence of '.' in
the string str. It returns -1 if str is NULL or str has no '.'
*/
int lastIndexDot(char* str) {
return -1;
}
/*
This function compares the relative ordering of file1 and file2.
The definition of ordering is given in the TMA paper.
It returns -1 if file1 < file2, returns 0 if file1 = file2,
and returns if file1 > file2
*/
int compareFilenames(char* file1, char* file2) {
return 0;
}
/*
The function inserts the newfile string into the binary tree pointed
by root. The funtcion returns the root pointer of the binary tree
with the newfile insert. The function does nothing but return NULL
if newfile already exists in the binary tree
*/
TreeNode* insertFilename(TreeNode* root, char* newfile) {
}
/*
This function prints the content of the binary tree in the inorder
traversals with counters.
*/
int printInorderWithCounter(TreeNode* root, int count) {
return 0;
}
/*
This function prints the content of the binary tree in the inorder
traversals
*/
void printInorder(TreeNode* root) {
if (root == NULL)
return;
printInorder(root->leftchild);
printf("%s\n", root->filename);
printInorder(root->rightchild);
}
int numberOfFiles(TreeNode* root) {
if (root == NULL)
return 0;
return numberOfFiles(root->leftchild) +
numberOfFiles(root->rightchild) + 1;
}
int main()
{
FILE* fp; /* file pointer for popen */
char buffer[256]; /* buffer for holding filename temporary */
TreeNode* root = NULL; /* the root pointer to the binary tree */
/*
declare other necessary variables
*/
fp = _popen("dir /a-d /b", "rt");
if (fp == NULL) {
printf("Error in listing directory\n");
}
/*
make changes to the following code
*/
while (fgets(buffer, 256, fp) != NULL) {
buffer[strlen(buffer)-1] = '\0'; /* removing the ending newline */
printf("%s\n", buffer);
}
}
I can compare the files using suffix.
I want to sort it out. Like .doc , .txt in a order