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
P r i va t e Member Functions: A private member functions can be called by the members of the same class.  Consider the following example.   c l a ss sample

Explain one-definition rule (ODR). According to one-definition rule, C++ constructs should be identically defined in each compilation unit they are used in. As per ODR, two

A: Use std::ios::binary. Some operating systems differentiate among text and binary modes. In text mode, end-of-line sequences and perhaps other things are translated; in binary

palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindromes

how to write a program using arrays

A container class is a class which is used to hold objects in external storage and memory. A container class work as a generic holder. A container class contains a predefined behav

Selecting Array Elements Implement the following C++ code in assembly language, using the block-structured .IF and .WHILE directives. Assume that all variables are 32-bit signed in


Aim: Write a program of multipication using inline function class Multiply {           int x,y;           public:           void getdata();           inline calc

What is Structure? An Array is a data structure whose elements are all of the similar data type. The structure is a data structure whose individual elements are able to differ