Advertisement
andruhovski

prog-ArrayFromFile

Sep 11th, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. int _tmain(int argc, _TCHAR* argv[])
  4. {
  5.     int N=10,i=0,*mas;
  6.     FILE *f;
  7.     fopen_s(&f,"massiv.txt","rt");
  8.     if (f==NULL) {
  9.         printf("Error in file!");
  10.         return -1;
  11.     }
  12.     mas = (int *) malloc(sizeof(int)*N);
  13.     while (!feof(f))
  14.     {
  15.         int val=0;
  16.         fscanf_s(f,"%d",&mas[i++]);
  17.         if (i==N)
  18.         {
  19.             N+=5;
  20.             mas=(int *) realloc(mas, sizeof(int)*N);
  21.         }
  22.     }
  23.     for (int k=0; k<i-1; k++)
  24.         printf ("%d\t", mas[k]);
  25.     fclose(f);
  26.     printf("It's OK!\n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement