Wednesday, June 22, 2016

File Management

code : how to read data from a file and write output in anther file


///Bis-millah-hir-rahmanir-rahim.
//arafat,sylhet engineering college,Bangladesh.

///****Love coding, love solving problems. --Coder shall be coder.******


#include<bits/stdc++.h>
using namespace std;

#define pi acos(-1)
#define nl endl
#define sp " "
#define msa 200010
#define pf printf
#define sc scanf
#define pb push_back
#define pob pop_back

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;


int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);

    FILE *f,*f2; ///tow pointer for read and write
    int a,b,c;
    f = fopen("file.txt","r"); ///you must create a file(any name, here file.txt)
    f2 = fopen("out.txt", "w"); /// create another file or it will create itself (just rename the file here)
    fscanf(f,"%d %d",&a,&b); ///fscanf is a function for reading data from file
    c=a+b;
    fprintf(f2,"%d\n",c); /// fprintf is a function for writing data to a file
    fclose(f); /// close the input file
    fclose(f2); /// close the output file



    return 0;
}

No comments:

Post a Comment

Speedup Android Studio

Go to Help ->Edit Custom VM Options, and chnge this 4 setting. After that close your Android Studio. This settings are for 8gb of ram pc...