Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int main(int argc, char *argv[]){
  6.  
  7.         if (argc == 1){
  8.                 fprintf(stderr,"Adjon meg egy számot!\n");
  9.                 return 0;
  10.         }
  11.         FILE *f = fopen("szamok.txt","w+");
  12.         int n = atoi(argv[1]);
  13.         char c;
  14.         srand(time(NULL));
  15.         int szam;      
  16.         for (int i = 0; i < n; i++){
  17.                 fprintf(f,"%d\n",rand()%(50-2+1)+2);
  18.         }
  19.         fseek(f,1,SEEK_SET);
  20.         FILE *g = fopen("szamok2.txt","w+");
  21.         while (1){
  22.                 fscanf(f,"%d",&szam);
  23.                 if (feof(f)) break;
  24.                 fprintf(g,"%d\n",szam);
  25.         }
  26.         fclose(f);
  27.         fclose(g);
  28.  
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement