Showing posts with label C প্রোগ্রামিং - চোদ্দ অধ্যায় -FILE. Show all posts
Showing posts with label C প্রোগ্রামিং - চোদ্দ অধ্যায় -FILE. Show all posts

Saturday, February 7, 2015

FILE - 2

File

 

 

#include<stdio.h>
#include<stdlib.h>
int main()
{
    freopen ("input.txt","r",stdin);
    freopen ("output.txt","w",stdout);
    int n;
 
    while(scanf("%d",&n)!=EOF)
    {
        printf("%d\n",n);
    }
 
    return 0;
}

 



//file compare
 
 
#include<stdio.h>
int main()
{
    FILE *p,*q;
    int a,b;
    p=fopen("1.txt","r");
    q=fopen("2.txt","r");
 
    while(fscanf(p,"%d",&a)!=EOF)
    {
        fscanf(q,"%d",&b);
        if(a!=b)
        {
            printf("Wrong ans\n");
            return 0;
        }
    }
    printf("Accepted\n");
    fclose(p);
    fclose(q);
    return 0;
}

 



 
#include<stdio.h>
#include<stdlib.h>
int main()
{
    FILE *fp;
    char str [100]="sharif";
    char str2[100];
 
    fp = fopen ("Newfile.txt","r");
    str2[0]=getc(fp);
    //putc (str[0],fp);
    putchar (str[0]);
    fclose(fp);
 
    return 0;
}

 



 
#include<stdio.h>
#include<stdlib.h>
int main()
{
    FILE *fp;
    char str [100]="sharif";
    char str2[100];
 
    // fp = fopen ("Newfile.txt","w");
    fp = fopen ("Newfile.txt","r");
 
    //fputs(str,fp);
    fgets(str2,3,fp);
    printf("%s",str2);
    fclose(fp);
 
 
    return 0;
}

FILE - 1

file

 

 
#include<stdio.h>
#include<stdlib.h>
int main()
{
    FILE *fp;
    fp = fopen("Nex.txt","w");
    fprintf(fp,"THis is my friend\n");
    fclose(fp);
    return 0;
}

 



 
#include<stdio.h>
#include<stdlib.h>
int main()
{
    FILE *fp;
    fp = fopen("Nex.txt","a");
    fprintf(fp,"THis is my friend");
    fclose(fp);
    return 0;
}

 



 
#include<stdio.h>
#include<stdlib.h>
int main()
{
    FILE *fp;
    int n;
    fp = fopen("Nex.txt","r");;
    fscanf(fp,"%d",&n);
    printf("\n%d\n",n);
    fclose(fp);
    return 0;
}

 



 
#include<stdio.h>
#include<stdlib.h>
int main()
{
    FILE *fp;
    int n;
    fp = fopen("Nex.txt","w");
    scanf("%d",&n);
    fprintf(fp,"\n%d\n",n);
    fclose(fp);
 
    fp = fopen("Nex.txt","r");
    fscanf(fp,"%d",&n);
    printf("%d\n",n);
    fclose(fp);
 
 
    return 0;
}

 



 
#include<stdio.h>
#include<stdlib.h>
int main()
{
    FILE *fp,*fp1,*fp2;
    char ch[100];
    fp=fopen("file1.txt","w");
    scanf("%s",ch);
    fprintf(fp,"%s",ch);
    fclose(fp);
//.......................
     fp1 = fopen("file11.txt","r");
     if(fp1==NULL)
     {
         printf("File not found");
     }
     fp2 = fopen("file2.txt","w");
     fscanf(fp1,"%s",ch);
     fprintf(fp2,"%s",ch);
 
fclose(fp1);
fclose(fp2);
 
}