Write in a file - c program, C/C++ Programming

Write in a file:

void main()

{

int i,j,k,l,list[1000];

FILE *fp;

char any[8];

 

cout << "Enter a file name\n";

cin >> any;

 

fp = fopen(any,"wb");

    for(j=0;j<50;j++)

    {

       for(i=0;i<200;i++)

       {

                   k = rand() % RAND_MAX;

                   fwrite(&k,sizeof(int),1,fp);

       }

    }

/*fclose(fp);

 

fp = fopen(any,"rb");   */

    i = 0;

    while (fread(&l,sizeof(int),1,fp) != 0)

    {

                  list[i] = l;

                  i = i + 1;

    }

fclose(fp);

 

for (i=0;i<50;i++)

    cout << list[i] << '\n';

 

/*for(i=0;i<900;i++)

    {

                k = list[i];

                fwrite(&k,sizeof(int),1,fp);

    }

 

fp = fopen("ggg.txt","wb");

    for(int a=1;a<900;a++)

    {

       int v = list[a];

       int b = a;

       while(list[b-1] > v)

       {

                   list[b] = list[b-1];

                   b = b - 1;

       }

       list[b] = v;

    }

    for(i=0;i<900;i++)

    {

                k = list[i];

                fwrite(&k,sizeof(int),1,fp);

    }

fclose(fp);    */

 

 

}

 

 

Posted Date: 10/18/2012 6:06:49 AM | Location : United States







Related Discussions:- Write in a file - c program, Assignment Help, Ask Question on Write in a file - c program, Get Answer, Expert's Help, Write in a file - c program Discussions

Write discussion on Write in a file - c program
Your posts are moderated
Related Questions
Using the Constructor There are basically three ways of creating and initializing the object. The first way to call the constructor is explicitly as :

hi i want wite a C++ program that get one logical phrase (included {x,y,z,w,1,0}) and simplify it! but i ''m confused! thanxs for anubody help me...

Need help finishing my homework. It''s been 5 years since I''ve use C++. I am a VN.Net programmer. -Todd

assume that the first integer read with cin specifies the number of values remaining to be entered. that program should read only one value each time cin is executed .a typical inp

Project Description: We are seeking someone to search mp3 link form audio or m3u8 for videos. Skills required are .NET, C Programming, Engineering, C# Programming

Various ways of initializing the Arrays. - The for loop initializes 10 elements with the value of their index.      void main()     {                 const in

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''''a''''-''''z'''') and

how to do an array

Write a ''C'' program to accept any 3 digit integer number from the keyboard and display the word equivalent representation of the given number.

After p = new Fred[n], how does the compiler know about n objects to be destructed throughout delete[] p? A:  The run-time system hold the number of objects, n, somewhere where