Sponsored Content
Top Forums UNIX for Advanced & Expert Users looking for a unix C program...help please Post 48718 by mani_kumar on Monday 15th of March 2004 06:04:32 AM
Old 03-15-2004
#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...
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help with UNIX Program

I am trying to set up a file for someone and they have a program that was built for UNIX. I am guessing that it is running in some sort of emulator since they are on WinXP. It is a database and we are trying to get all of the addresses out of the database. I talked to the tech support for the... (7 Replies)
Discussion started by: brand1m
7 Replies

2. Programming

getting username from a c program in unix

How to get the user name of the Operating system from a c program. eg:- -rw-r----- 1 gkuser srth1 292 Jul 27 19:28 u1.txt i need to get gkuser as the result? (3 Replies)
Discussion started by: Rajeshsu
3 Replies

3. Shell Programming and Scripting

Sorting Program In UNIX

Write a shell program that takes one or any number of file names as input; sorts the lines of each file in ascending order and displays the non blank lines of each sorted file and merge them as one combined sorted file. The program should generate an error message in case any input file does not... (1 Reply)
Discussion started by: kumar_saurabh
1 Replies

4. UNIX for Dummies Questions & Answers

UNIX program?

Is there a program out there than runs like the UNIX operating system except in Window mode on Windows XP? Kind of like command prompt cmd.exe? (1 Reply)
Discussion started by: threewingedfury
1 Replies

5. Programming

compiling c program in unix

if somebody can help me pls. i need the source code for a shell which compiles C or java programs in unix i need a very short and simple one, just the compiling part Respect (2 Replies)
Discussion started by: zlatan005
2 Replies

6. UNIX for Advanced & Expert Users

C socket program on UNIX

Write a C socket program on UNIX where a TCP client sends/reads a time in decimal 24 hours format to the server and the server echoes the seconds, minutes, and hours in the time. Example: Client sends 18.78 hours and the server displays 18 hours, 46 minutes and 48 seconds. (1 Reply)
Discussion started by: adi_always4u143
1 Replies

7. Homework & Coursework Questions

Need help with Basic Unix Program

I am a newbie to UNIX. I'm learning UNIX on my own, just trying to get the jerk of how things work in UNIX environment. I am familiar with Windows environment. Can anyone pls write simple 'envprint' programs to : 1) List all the environment Information (using the -l or --l options) 2) ... (1 Reply)
Discussion started by: agup17
1 Replies

8. Shell Programming and Scripting

Running C program in UNIX

I want to run a C program from my BASH script. Here's some very basic simplified code of my bash script: #!/bin/bash echo "Run C program" ./main.c echo "Ran C program" Here's my main.c: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv) { ... (3 Replies)
Discussion started by: millsy5
3 Replies

9. Shell Programming and Scripting

C program into UNIX?

Hello folks! I need help on this one: I have this C known program which I need to save it as "power2.c", and create it as a file in my UNIX environment: /* power2.c -- Print out powers of 2: 1, 2, 4, 8, .. up to 2^N */ #include #define N 16 int main(void) { int n; /* The current... (1 Reply)
Discussion started by: kinelisch
1 Replies

10. Homework & Coursework Questions

C program into UNIX?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Do not know how to implement this into a script in Unix?:confused: 2. Relevant commands, code, scripts,... (8 Replies)
Discussion started by: kinelisch
8 Replies
GETCWD(3)						   BSD Library Functions Manual 						 GETCWD(3)

NAME
getcwd, getwd -- get working directory pathname LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <unistd.h> char * getcwd(char *buf, size_t size); char * getwd(char *buf); DESCRIPTION
The getcwd() function copies the absolute pathname of the current working directory into the memory referenced by buf and returns a pointer to buf. The size argument is the size, in bytes, of the array referenced by buf. If buf is NULL, space is allocated as necessary to store the pathname. This space may later be free(3)'d. The function getwd() is a compatibility routine which calls getcwd() with its buf argument and a size of MAXPATHLEN (as defined in the include file <sys/param.h>). Obviously, buf should be at least MAXPATHLEN bytes in length. These routines have traditionally been used by programs to save the name of a working directory for the purpose of returning to it. A much faster and less error-prone method of accomplishing this is to open the current directory ('.') and use the fchdir(2) function to return. RETURN VALUES
Upon successful completion, a pointer to the pathname is returned. Otherwise a NULL pointer is returned and the global variable errno is set to indicate the error. In addition, getwd() copies the error message associated with errno into the memory referenced by buf. ERRORS
The getcwd() function will fail if: [EINVAL] The size argument is zero. [ENOENT] A component of the pathname no longer exists. [ENOMEM] Insufficient memory is available. [ERANGE] The size argument is greater than zero but smaller than the length of the pathname plus 1. The getcwd() function may fail if: [EACCES] Read or search permission was denied for a component of the pathname. This is only checked in limited cases, depending on implementation details. SEE ALSO
chdir(2), fchdir(2), malloc(3), strerror(3) STANDARDS
The getcwd() function conforms to ISO/IEC 9945-1:1990 (``POSIX.1''). The ability to specify a NULL pointer and have getcwd() allocate memory as necessary is an extension. HISTORY
The getwd() function appeared in 4.0BSD. BUGS
The getwd() function does not do sufficient error checking and is not able to return very long, but valid, paths. It is provided for compat- ibility. BSD
April 17, 2010 BSD
All times are GMT -4. The time now is 06:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy