Skip to content

Instantly share code, notes, and snippets.

@vertrigo
Created November 16, 2012 17:05
Show Gist options
  • Select an option

  • Save vertrigo/4089025 to your computer and use it in GitHub Desktop.

Select an option

Save vertrigo/4089025 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main(void)
{
int x,y,k;
FILE*f,*g;
f=fopen("lab5.dat","w");
printf("Введите X Y (признак окончания ввода X=0 Y=0):\n");
do {
scanf("%i %i",&x,&y);
fwrite(&x,sizeof(x),2,f);
fwrite(&y,sizeof(y),2,f);
} while (x != 0 || y != 0);
fclose(f);
printf("Содержимое файла:\n");
if ((f=fopen("lab5.dat","r"))==NULL)
{
printf("Ошибка чтения файла\n");
return;
}
g=fopen("lab5.txt","w");
fprintf(g," Содержимое файла:\n");
k=0;
do {
fread(&x,sizeof(x),2,f);
fread(&y,sizeof(y),2,f);
if(!feof(f))
{
printf("%4i",x);
printf("%4i",y);
fprintf(g,"%4i",x);
fprintf(g,"%4i",y);
//if (x*x+y*y>=4) {k++;}
}
} while (!feof(f));
//printf("\n KOL-VO TOCHEK VNE KRUGA=%i\n",k);fprintf(g,"\nKOL-VO TOCHEK VNE KRUGA=%i\n",k);
fclose(f); fclose(g);
getch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment