#include <iostream>
#include <fstream>


using namespace std;

size_t n=50;
size_t count=0;
char names[50][20];


void ReadNames(istream & f)
{
while(!f.eof())
{
if(f.peek()=='\n')
f.ignore();

if(f.eof())
break;


f.getline(names[count],20,',');

count++;

}
}

void PrintNames(ostream & q)
{
for(size_t k=0; k<count; k++)
q << names[k] << endl;
}

int main()
{

fstream f("names.txt");

if(!f.good())
{
cerr << "Error opening file" << endl;
return -1;
}

ReadNames(f);

cerr << "Names count = " << count << endl;

PrintNames(cout);
return 0;
}

Последно модифициране: събота, 12 ноември 2011, 17:38