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 |
Quote:
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. |
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. |