Write C program that simulate the following unix commands mv and cp - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Thursday, October 6, 2011

Write C program that simulate the following unix commands mv and cp



Write  C program that simulate the following unix commands
(a) mv
 (b) cp

#include<fcntl.h>
#include<unistd.h>
#include<stdio.h>
main(int argc,char *argv[])
{
FILE *fp;
char ch;
int sc=0;

fp=fopen(argv[1],"r");
if(fp==NULL)
   printf("unable to open a file",argv[1]);
else
{
  while(!feof(fp))
  {
   ch=fgetc(fp);
   if(ch==' ')
   sc++;
 }
  printf("no of spaces %d",sc);
  printf("\n");
  fclose(fp);
 }
}

No comments:

Post a Comment