Monday, May 24, 2010

Write a c program that will generate an arbitrary number of integers and store them in the file name numfile?

the c program one integer per line

Write a c program that will generate an arbitrary number of integers and store them in the file name numfile?
#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;





int


main(int argc, char* argv[])


{


  int count = argc%26gt;1 ? atoi(argv[1]) : 10;


  FILE *f = fopen("numfile", "w+");


  if (!f)


    perror("fopen"), exit(-1);


  for (int i=0; i%26lt;count; i++)


    fprintf(f, "%d\n", rand());


  fclose(f);


  return 0;


}


No comments:

Post a Comment