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

Assignment Help:

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);    */

 

 

}

 

 


Related Discussions:- Write in a file - c program

Displays the temperature conversion chart on the screen, Write a program th...

Write a program that displays the following temperature conversion chart on the screen as follows below. Hint: c = 5.0/9.0 * (f - 2) C = degrees in Celsius F = degree in F

Explain external variables, External Variables Different functions of t...

External Variables Different functions of the similar program can be written in different source files and can be compiled together. The scope of a global variable is not limit

C code, how can i easily make a program?

how can i easily make a program?

Palindorme, program coding for the conversion of string to a palindrome

program coding for the conversion of string to a palindrome

Program to list the cities and their states, The program will ask the user ...

The program will ask the user to enter: '1' to List the cities(and their state abbrev)  from largest to smallest (by their population) with their population '2'  to List the

Explain zero based addressing, Explain zero based addressing. - Array s...

Explain zero based addressing. - Array subscripts always start at zero. - These subscript values are used to identify elements in the array. - As subscripts start at 0, a

When should you employ multiple inheritance?, Q: When should you employ mul...

Q: When should you employ multiple inheritance? A:There  are  three  acceptable  answers:-  "Rarely," "Never," and  "while  the  problem  domain cannot be modeled accurately any

Program to calculate students marks, #include using namespace std; void...

#include using namespace std; void print(int marks_arr[],int cnt) { int ind[cnt]; int i=0; int j=0; int k=0; int s=0; for(k=0;k { ind[k]=0; } int cnt1=0; for(i=0;i

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd