-->

Program to store integers in a data file

using codeblocks
------------------------------------------------------------------------------------------------------
//using putw() to store data(one integer) from an opened file
#include <stdio.h>
#include<stdlib.h>                       // header file for system("cls")
int main()

{

    FILE *p;                               //pointer declaration
    char ch;
    int i;
    system("cls");                         //clears the screen/console
    p=fopen("data1.txt","w");               //file opening in write mode
    printf("first we store/write data in an opened file\n");
    for(i=0;i<=40;i++)             //executes the loop
    {
         putw(i,p);                // write the entered integer in that file
            }
    fclose(p);                              //closes the file
getch();
return 0;
}
--------------------------------------------------------------------------------------------
usnig turboc++
--------------------------------------------------------------------------------------------------
//using putw() to store data(one integer) from an opened file
#include <stdio.h>
#include<stdlib.h>                       // header file for system("cls")
#include<conio.h>
int main()

{

    FILE *p;                               //pointer declaration
    char ch;
    int i;
    system("cls");                         //clears the screen/console
    p=fopen("data1.txt","w");               //file opening in write mode
    printf("first we store/write data in an opened file\n");
    for(i=0;i<=40;i++)             //executes the loop
    {
         putw(i,p);                // write the entered integer in that file
            }
    fclose(p);                              //closes the file
getch();
return 0;
}


No comments:

Post a Comment