LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how can i simulate the cp command by modifying this C code? (C people i want help!) (https://www.linuxquestions.org/questions/programming-9/how-can-i-simulate-the-cp-command-by-modifying-this-c-code-c-people-i-want-help-771264/)

linuxFreshMan 11-24-2009 12:01 PM

how can i simulate the cp command by modifying this C code? (C people i want help!)
 
1 Attachment(s)
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):
#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.. PLEASE send it to me.. either here or via e-mail: zol_sudani@hotmail.com

johnsfine 11-24-2009 12:19 PM

Quote:

Originally Posted by linuxFreshMan (Post 3768157)
back at the collage they asked us to simulate the cp command by modifying the C code below

I reported your other thread for moderator action for being a duplicate and for being in the wrong forum.

But even this one seems to be a direct "do my homework for me" post.

Make some attempt at doing your own homework. Post questions about specific details you might have trouble with. Do not just post the original assignment.

Also, learn how to use code tags, so you can post readable code.

linuxFreshMan 11-24-2009 10:36 PM

hi, am really sorry, this shall never happen again.. am going to try it my self, then if i faced any trouble i shall ask about it,, thanks a lot..


All times are GMT -5. The time now is 08:11 PM.