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
C Program to FIND THE EVEN WORDS IN THE STRING #include conio.h> #include stdio.h> void main() {           char a[50],temp;           int i=0,k=0,l[25],c=0,r=0;

recsection method source code for searching position

d) a "static destructor" is a static member function of the class which accepts one argument - a pointer to the object of that class to be cracked. It is probably utilized along wi

Here is a program that uses an inline function to compute and return the absolute value of its input argument. # include inline int abs(int x) {                  ret

New data members  New member functions  New constructors and destructor  New friends

What's the order that objects in an array are destructed? Need assistance please explain it with example.

The #define Directive The #define directive explains a macro which is a text string represented by a name. Whenever the pre-processor finds this name in the program, it is repl

Inline function: It is a function without prototype. The function is defined above main. The function should  be  declared  above  main  function.                  Declaring

calculate the total resisitance of a series circuit?

write a program for convert numbers upto 9 to alphabet?Eg.now enter the inputis 666 means output is "0" lphabet