LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


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

Rep: Reputation: 0
Question 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):
#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
Attached Files
File Type: txt fileoperations.txt (561 Bytes, 21 views)
 
Old 11-24-2009, 12:19 PM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by linuxFreshMan View Post
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.

Last edited by johnsfine; 11-24-2009 at 12:21 PM.
 
Old 11-24-2009, 10:36 PM   #3
linuxFreshMan
Member
 
Registered: Nov 2009
Distribution: Ubuntu 9, RedHatLinux
Posts: 47

Original Poster
Rep: Reputation: 0
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..
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
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
LXer: People Behind KDE: Summer of Code 2007 (4/4) LXer Syndicated Linux News 0 10-07-2007 06:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:45 AM.

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