Главная » 2016 » Апрель » 12 » файлы С, запись и чтение
08:48
файлы С, запись и чтение

#include <iostream>
#include <ctime>
using namespace std;
void infile(FILE *f, char *s)
{
    int n,dat;
    f=fopen(s,"wb");
    n=rand()%100+1;
    for (int i=0;i<n;i++)
    {
        dat=rand();
        fwrite(&dat,sizeof(int),1,f);
    }
    fclose(f);
}
void outfile(FILE *f, char *s)
{
    int dat;
    f=fopen(s,"rb");
    while (fread(&dat,sizeof(int),1,f))
    {
        cout<<dat<<endl;
    }
    fclose(f);
}
int main()
{
    setlocale(LC_ALL,"rus_rus.1251");
    srand(time(0));
    char s[80]="d:\\1.txt";
    FILE *f;
    infile(f,s);
    outfile(f,s);
    system("pause");
    return 0;
}

Просмотров: 328 | Добавил: denjes | Рейтинг: 5.0/1
Всего комментариев: 0
avatar