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;
}

No comments:

Post a Comment