File Programming

#include<stdio.h>

    int main()
    {
        FILE *ptr_file;
        int x;

        ptr_file =fopen("output.txt", "w");

        if (!ptr_file)
            return 1;

        for (x=1; x<=10; x++)
            fprintf(ptr_file,"%d\n", x);

        fclose(ptr_file);

        return  0;
    }

2 comments:

  1. #include

    int main()
    {
    FILE *fp;
    int i;

    fp =fopen("write.txt", "w");

    if (!fp)
    return 1;

    for (i=1; i<=100; i++)
    fprintf(fp,"%d ", i);

    fclose(fp);

    return 0;
    }

    ReplyDelete
  2. #include

    int main()
    {
    FILE *hp;
    int a;

    hp =fopen("output.txt", "w");

    if (!hp)
    return 1;

    for (a=1; a<=10; a++)
    fprintf(hp,"%d\n", a);

    fclose(hp);

    return 0;
    }

    ReplyDelete