hi every one, am really a newbie in both linux and C programming language.. back at the collage they asked us to simulate the cp command by modifying the C code below (it was doing the 'ls' job at the beginning):
Code:
#include<unistd.h>
#include<stdio.h>
#include<dirent.h>
#include<string.h>
#include<sys/stat.h>
#include<stdlib.h>
void printdir(char *dir)
{
DIR *dp;
struct dirent *entry;
struct stat info;
if((dp=opendir(dir))==NULL)
{
write(2,"cannot open directory\n",22);
return;
}
chdir(dir);chdir(dir);
while((entry=readdir(dp))!=NULL)
{
printf("\n%s",entry->d_name);
stat(entry->d_name,&info);
if(S_ISDIR(info.st_mode)){
if(strcmp(entry->d_name,".")==0)
continue;
printf("/");
printdir(entry->d_name);}
}
closedir(dp);
}
int main()
{
printdir("Mustafa");
return 0;
}
note1: if help can be provided in a form of source code, that shall be very good and helpful.. just modifying the above code..
note2: this code was basically written to simulate the 'ls' command..
now if any one can provide the modifications needed to this code to work..
thanks