-->

program to read that stored integers using getw

using codeblocks
-----------------------------------------------------------------------------
#include <stdio.h>
int main()
{
    FILE *p;                               //pointer declaration
    char ch;
p=fopen("data1.txt","r");               // openes the file in read only mode
    while((i=getw(p))!=EOF)              //read an  integer using getw from opened file.
    {

        printf("%d,",i);                //prints that integer on screen
    }
    fclose(p);                            //closes the file
    return 0;
}

----------------------------------------------------------------------------------------
using turboc++
-----------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include<conio.h>
int main()
{
    FILE *p;                               //pointer declaration
    char ch;
p=fopen("data1.txt","r");               // openes the file in read only mode
    while((i=getw(p))!=EOF)              //read an  integer using getw from opened file.
    {

        printf("%d,",i);                //prints that integer on screen
    }
    fclose(p);                            //closes the file
    getch();
    return 0;
}

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


program to store a number and to read that using putw and getw

using codeblocks
---------------------------------------------------------------------------------------------------------------
//using putw() to store data(one integer) and getw() to read (one integer)that data 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
    {
       // fprintf(p,"%d\n",i);                        // write the entered integer in that file
        putw(i,p);
    }
    fclose(p);                              //closes the file
    printf("data/numbers stored successfully!!!\n");
    printf("now we are going to read that stored data\n");
    p=fopen("data1.txt","r");               // openes the file in read only mode
    while((i=getw(p))!=EOF)    //read an integer using getw from opened file.
    {

        printf("%d,",i);                //prints that integer on screen
    }
    fclose(p);                            //closes the file
    return 0;
}
//note: The second part (reading file), we can include in
//different file rather in same file as written here.
// But we have to know its data file name.
//i mean to say, the code would be :

/*
#include <stdio.h>
int main()
{
    FILE *p;                               //pointer declaration
    char ch;
p=fopen("data1.txt","r");               // openes the file in read only mode
    while((i=getw(p))!=EOF)              //read an  integer using getw from opened file.
    {

        printf("%d,",i);                //prints that integer on screen
    }
    fclose(p);                            //closes the file
    return 0;
}
*/
-----------------------------------------------------------------------------
using turboc++
------------------------------------------------------------------------------------------
//using putw() to store data(one integer) and getw() to read (one integer)that data 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
    {
       // fprintf(p,"%d\n",i);                        // write the entered integer in that file
        putw(i,p);
    }
    fclose(p);                              //closes the file
    printf("data/numbers stored successfully!!!\n");
    printf("now we are going to read that stored data\n");
    p=fopen("data1.txt","r");               // openes the file in read only mode
    while((i=getw(p))!=EOF)    //read an integer using getw from opened file.
    {

        printf("%d,",i);                //prints that integer on screen
    }
    fclose(p);                            //closes the file
   getch();
    return 0;
}
//note: The second part (reading file), we can include in
//different file rather in same file as written here.
// But we have to know its data file name.
//i mean to say, the code would be :

/*
#include <stdio.h>
int main()
{
    FILE *p;                               //pointer declaration
    char ch;
p=fopen("data1.txt","r");               // openes the file in read only mode
    while((i=getw(p))!=EOF)              //read an  integer using getw from opened file.
    {

        printf("%d,",i);                //prints that integer on screen
    }
    fclose(p);                            //closes the file
    return 0;
}
*/

Program to store data/character in an opened file then read that character and print on screen in same program.

using codeblocks
----------------------------------------------------------------------------------------------------------------
//using putc() to store data(one character) and getc() to read (one character)that data from an opened //file
#include <stdio.h>
int main()
{
    FILE *p;                               //pointer declaration
    char ch;
    p=fopen("data.txt","w");               //file opening in write mode
    printf("first we store/write data in an opened file\n");
    printf("press ctrl+z to exit\n");
    while((ch=getchar())!=EOF)              //gets one character until you press ctrl+z/terminate the input
    {
        putc(ch,p);                        // write the entered character in that file
    }
    fclose(p);                              //closes the file
    printf("data stored successfully!!!\n");
    printf("now we are going to read that stored data\n");
    p=fopen("data.txt","r");               // openes the file in read only mode
    while((ch=getc(p))!=EOF)               //read a character using getc from opened file.
    {
        putchar(ch);                      //prints that character on screen
    }
    fclose(p);                            //closes the file
    return 0;
}
//note: The second part (reading file), we can include in
//different file rather in same file as written here.
// But we have to know its data file name.
//i mean to say, the code would be :

/*#include <stdio.h>
int main()
{
    FILE *p;                               //pointer declaration
    char ch;
    printf("now we are going to read that stored data\n");
    p=fopen("data.txt","r");               // openes the file in read only mode
    while((ch=getc(p))!=EOF)               //read a character using getc from opened file.
    {
        putchar(ch);                      //prints that character on screen
    }
    fclose(p);                            //closes the file
    return 0;
}
*/
------------------------------------------------------------------------------------------------------------
using turboc++
---------------------------------------------------------------------------------------
//using putc() to store data(one character) and getc() to read (one character)that data from an opened //file
#include <stdio.h>
#include<conio.h>
int main()
{
    FILE *p;                               //pointer declaration
    char ch;
    p=fopen("data.txt","w");               //file opening in write mode
    printf("first we store/write data in an opened file\n");
    printf("press ctrl+z to exit\n");
    while((ch=getchar())!=EOF)              //gets one character until you press ctrl+z/terminate the input
    {
        putc(ch,p);                        // write the entered character in that file
    }
    fclose(p);                              //closes the file
    printf("data stored successfully!!!\n");
    printf("now we are going to read that stored data\n");
    p=fopen("data.txt","r");               // openes the file in read only mode
    while((ch=getc(p))!=EOF)               //read a character using getc from opened file.
    {
        putchar(ch);                      //prints that character on screen
    }
    fclose(p);                            //closes the file
     getch();
    return 0;
}

Program to read data/character from opened file.

using codeblocks
----------------------------------------------------------------------------------
//using getc() to read (one character)that data from an opened
 #include <stdio.h>
int main()
{
    FILE *p;                               //pointer declaration
    char ch;
    printf("now we are going to read that stored data\n");
    p=fopen("data.txt","r");           // openes the file in read only mode. We should know the file name.
    while((ch=getc(p))!=EOF)               //read a character using getc from opened file.
    {
        putchar(ch);                      //prints that character on screen
    }
    fclose(p);                            //closes the file
    return 0;
}
-------------------------------------------------------------------------------------------
using turboc++
-----------------------------------------------------------------------------------------------------------

//using getc() to read (one character)that data from an opened
 #include <stdio.h>
#include<conio.h>
int main()
{
    FILE *p;                               //pointer declaration
    char ch;
    printf("now we are going to read that stored data\n");
    p=fopen("data.txt","r");           // openes the file in read only mode. We should know the file name.
    while((ch=getc(p))!=EOF)               //read a character using getc from opened file.
    {
        putchar(ch);                      //prints that character on screen
    }
    fclose(p);                            //closes the file
getch();
    return 0;
}

Program to store data/character in a datafile

using codeblocks
--------------------------------------------------------
//using putc() to store data(one character) and getc() to read (one character)that data from an opened file
#include <stdio.h>
int main()
{
    FILE *p;                               //pointer declaration
    char ch;
    p=fopen("data.txt","w");               //file opening in write mode
    printf("first we store/write data in an opened file\n");
    printf("press ctrl+z to exit\n");
    while((ch=getchar())!=EOF)              //gets one character until you press ctrl+z/terminate the input
    {
        putc(ch,p);                        // write the entered character in that file of pointer 'p'.
    }
    fclose(p);                              //closes the file
  }
-------------------------------------------------------------------------------------------------
using turbo c++
----------------------------------------------------------------------------------------
//using putc() to store data(one character) and getc() to read (one character)that data from an opened file
#include <stdio.h>
#include<conio.h>
int main()
{
    FILE *p;                               //pointer declaration
    char ch;
    p=fopen("data.txt","w");               //file opening in write mode
    printf("first we store/write data in an opened file\n");
    printf("press ctrl+z to exit\n");
    while((ch=getchar())!=EOF)              //gets one character until you press ctrl+z/terminate the input
    {
        putc(ch,p);                        // write the entered character in that file of pointer 'p'.
    }
    fclose(p);                              //closes the file
getch();
  }