LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Closed Thread
  Search this Thread
Old 11-24-2009, 12:05 PM   #1
linuxFreshMan
Member
 
Registered: Nov 2009
Distribution: Ubuntu 9, RedHatLinux
Posts: 47

Rep: Reputation: 0
how can i simulate the cp command by modifying this C code? (C people i want help!)


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

Last edited by XavierP; 11-24-2009 at 01:35 PM.
 
Old 11-24-2009, 01:35 PM   #2
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.

Go here for code-y goodness: http://www.linuxquestions.org/questi...t-help-771264/
 
  


Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i simulate the cp command by modifying this C code? (C people i want help!) linuxFreshMan Programming 2 11-24-2009 10:36 PM
Modifying the output of the ls command valen_tino Red Hat 5 11-23-2009 04:09 PM
Standard way of telling people about CODE tags? Meson LQ Suggestions & Feedback 7 08-03-2009 09:40 AM
How to simulate scp command using ssh? vickylife Linux - Newbie 3 11-18-2008 05:22 AM
How to simulate closing a window from the command line with /usr/bin/killall? Winter Knight Linux - Desktop 5 11-10-2007 04:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration