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

Operation on array: void Array::add( Object& toAdd ) {     lastElementIndex++;     while( ptrAt( lastElementIndex ) != ZERO &&            lastElementIndex

What are Arrays? Numerous applications require the processing of multiple data items that have identical characteristics. In such circumstances it is frequently convenient to p

write a program that can accept numbers and perform all the four arithmetic operation

Construct a console program to manage the booking of a Hotel room.

draw the flow chart to print the fibonacci series upto n th terms

Relational Operators A relational operator is used to make comparison among two values. All these operators are binary and needs two operands. There are the following relationa

You're going to simulate a metropolitan subway train.  The train system will start out at Station #1, or Home  Station, and will service multiple stations along its route.

Goals For this assignment you will write programs in C and LC-3 assembly code. Both programs will perform the identical recursive algorithm. The goals of this programming assignmen

#include long BixFunction(int x, int y = 5, float z = 5) { return(++x * ++y + (int)++z); } int main() { cout return 0; }