File Remotio
Upcoming SlideShare
Loading in...5
×
 

File Remotio

on

  • 208 views

This presentation is about the shifting of file content from one file to another.

This presentation is about the shifting of file content from one file to another.
This is done using C programming .

Statistics

Views

Total Views
208
Views on SlideShare
208
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    File Remotio File Remotio Presentation Transcript

    • FILE Remotio - Niranjj.S CSE-A
    • Table of Contents  Introduction  What to do ?  Technique used  How it works ?  Applications  Queries
    • File Remotio CONTENTS Remotio – shifting  Introduction This is about the shifting of files in C language.  What to do ?  Technique used  How it works?  Applications  Queries The basic concept we all know about swapping is a=5 b=6 after shifting a=6 b=5 This could be done either by using temporary variable or by swap function. but how to do with files…?? Let’s switch to the question
    • Task with Condition CONTENTS  Introduction  What to do? Design a program that circularly swaps the contents of files. for example 3 files are taken as input then the content of file1 to file 2 then, file2 to file3 then, file3 to file1  Technique used The program should scale well to certain number of files.  How it works? Also assert the number of words in each file which will also should be changed when swapping is occurred .  Applications  Queries
    • CONTENTS File5 File1  Introduction  What to do ? Technique used (pictorial) File4 File2  How it works ?  Applications  Queries File3
    • STEP 1: Start the program . CONTENTS  Introduction STEP 2:Include the header files and function prototyes Declare the functions check and swp which are used then,the integer variables I,n and bf and aaf with array size 50. STEP 3: Declare the character variables txtbf and txtaf with array size 50 and assign the name of array as”a.txt”. STEP 3: Create a file pointer fp of size 50.  What to do ? STEP 4: Print the number of files to open and get in n. Technique used STEP 5: Initialize i equal to 0 and check whether it is less than n and if so it will create the new files and the contents will be displayed in file till n number of times else it will print “file is not created successfully. “. (Algorithm)  How it works?  Applications  Queries STEP 6: Again check the same condition and if it satisfied call the function check and store the content in bf then by the given statement the contents are copied to txtbf []. STEP 7: In the check function it initialize tlen o ‘0’and the count will be increased till it reaches the EOF (End Of File) and then the len will be returned . STEP 8: : Promote the same looping conditions and if it satisfied it calls the swp function
    • CONTENTS  Introduction  What to do ? Technique used (Algorithm)  How it works?  Applications  Queries STEP 9: In the swp function two variables t1 and t2 are created the contents of file 1 will be copied to t1 and t2 will be placed on file1and then t1 to t2 and the cycle will be continued till the condition satisfies . STEP 10: At last content of the file and the lengh of the file before and after swapping will be printed . STEP 11: Get the output and end the program.
    • #include<stdio.h> CONTENTS  Introduction  What to do ?  Technique used  How it works? (Source code) #include<string.h> int check(FILE *fp); void swp(FILE *fp); void main() { int i,n,bf[50],af[50]; char name[6]="a.txt",txtbf[50][50],txtaf[50][50]; FILE *fp[50]; clrscr();  Applications printf("Enter number of files to open :");  Queries scanf("%d",&n);
    • for(i=0;i<n;i++) { CONTENTS name[0]='a'+i;  Introduction if((fp[i]=fopen(name,"w+"))==0)  What to do ? { printf("nFile NOT created successfullyn");  Technique used }  How it works? (Source code) else {  Applications fprintf(fp[i],"%s%d","contents of file ",i+1);  Queries printf("File created successfullyn"); } }
    • for(i=0;i<n;i++) { CONTENTS bf[i]=check(fp[i]);  Introduction rewind(fp[i]);  What to do ? fgets(txtbf[i],49,fp[i]);  Technique used  How it works? (Source code) } for(i=0;i<n;i++) { swp(fp[i]);  Applications }  Queries swp(fp[0]);
    • for(i=0;i<n;i++) { CONTENTS af[i]=check(fp[i]);  Introduction rewind(fp[i]);  What to do ? fgets(txtaf[i],49,fp[i]);  Technique used } for(i=0;i<n;i++)  How it works? (Source code) { printf("nnBefore swapping : nFILE %d : %s",i+1,txtbf[i]);  Applications printf("nlength of FILE %d : %d",i+1,bf[i]);  Queries printf("nnAfter swapping : nFILE %d : %s",i+1,txtaf[i]); printf("nlength of FILE %d : %d",i+1,af[i]);
    • printf("n-------------------------------------------------");} getch(); CONTENTS }int check(FILE *fp)  Introduction { int len=0;  What to do ? rewind(fp);  Technique used while(getc(fp)!=EOF)  How it works? (Source code) { len++;  Applications }  Queries return len; }
    • void swp(FILE *fp)// receive fp CONTENTS { char t1[50],t2[50];  Introduction rewind(fp);  What to do ? fgets(t1,49,fp);  Technique used rewind(fp);  fputs(t2,fp); How it works? (Source code)  Applications  Queries strcpy(t2,t1); }
    • CONTENTS  Introduction  What to do ?  Technique used  How it works? (Output)  Applications  Queries
    • CONTENTS  Introduction  What to do ?  Technique used  How it works? Applications  Queries How it is used • It will be useful for those who wants to shift the entire stuff from one place to another that is to transfer the whole thing. • It is also useful to analyze the total number of contents in each file before shifting that is to verify it before it proceed • Keeping this as the base and doing further development this application can be used significantly in many other aspects