The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
unix awk/sed program mnnarendra UNIX for Advanced & Expert Users 4 03-26-2008 06:00 AM
UNIX program? threewingedfury UNIX for Dummies Questions & Answers 1 02-05-2008 11:15 AM
How do i run a program while in Unix?.... Corrail UNIX for Dummies Questions & Answers 4 10-31-2005 10:51 AM
Help with UNIX Program brand1m UNIX for Dummies Questions & Answers 7 02-28-2005 04:55 AM
running a c/c++ program in unix kray High Level Programming 2 07-12-2002 12:25 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-11-2004
Registered User
 

Join Date: Mar 2004
Location: Kingston, Jamaica
Posts: 9
Question looking for a unix C program...help please

Hey Guys,

Does anyone have a copy of a c-program which saves/writes files to a sub-directory within the home directory which uses the prototype::: save (char* filename, char* directory_name)::: if at all possible, could share that syntax with me please.

Thanx much.....
Peace...
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-15-2004
Registered User
 

Join Date: Mar 2004
Posts: 7
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
#include<fcntl.h>
#include<dir.h>


void save(char*, char*);

void save(char *fstr, char *dstr) {

char *str;

int fd;

char buf[100];

str = getcwd(dstr,100);


if((strcmp(str,"./"))==0)
{

mkdir("./dstr");

}

else {


fd = open(fstr,O_RDWR,0);

read(fd,buf,O_RDONLY,0);

if(!read)

{

exit(0);

}

chdir("./dstr/");

write(fd,buf,O_RDWR,0);

}

}


void main(){


/* pass the path of the current working directory as the second parameter*/

save("mani.txt","./manikumar/Mani");


}

please check the code

and run it...

you may get your problem solved....

Mani...
Reply With Quote
  #3 (permalink)  
Old 03-15-2004
Registered User
 

Join Date: Mar 2004
Location: Kingston, Jamaica
Posts: 9
Hey Mani,

Thankx much for the help... I really appreciate it. I'm yet to compile it, so, just as soon as I do, I'll keep you posted on the results ok. Thankx much.
Reply With Quote
  #4 (permalink)  
Old 03-15-2004
Registered User
 

Join Date: Mar 2004
Posts: 7
hey i forgot to add <string.h> so add it..
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:36 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0