void student::unpack()
{
	f.getline(usn,30,'|');
	f.getline(name,30,'|');
	f.getline(sem,30,'|');
	f.getline(dept,30,'\n');
}
Example #2
0
/**
 * \brief     Format the node comments
 * \param[in] fileInput Input file
 * \param[in] m_listComment List of CComments
 *
 * Parses the node comments.
 */
void CComment::Format_nodeComment(fstream& fileInput, list<CComment>& m_listComment)
{
    char* pcToken;
    char* pcNextToken;
    char* pcLine;
    char acLine[defCON_MAX_LINE_LEN];
    string comment;

    //Reads all the node comments,parses the comments and stores them to a list.
    while(fileInput.getline(acLine, defCON_MAX_LINE_LEN) && strcmp(acLine, "[END_DESC_NODE]")!=0)
    {
        pcLine=acLine;
        //reads the node name.
        pcToken=strtok_s(pcLine, " ", &pcNextToken);
        m_elementName=pcToken;
        //m_elementName = m_elementName.Left(defCON_MAX_MSGN_LEN);
        //get the comment.
        pcToken = strtok_s(NULL, "", &pcNextToken);
        comment = pcToken;

        while(strstr(pcToken,"\";") == NULL)
        {
            //parses the comment.
            fileInput.getline(acLine,defCON_MAX_LINE_LEN);
            pcToken = acLine;
            comment += pcToken;
        }

        m_comment= comment;
        //adds the comment to the list.
        m_listComment.push_back(*this);
    }
}
Example #3
0
void createReadNames(fstream& type1, char* nameStr)
{
   fstream out(nameStr, fstream::out);

   char line[1024];
   char name[100];
   char token[100];

   bool ignoreFirstLine = true;
   while(!type1.eof())
   {
      if (ignoreFirstLine)
      {
         type1.getline(line, 1024);
         ignoreFirstLine = false;
      }

      type1 >> name;
			if (!strcmp(name, "END"))
      {
         type1.getline(line, 1024); //ignoring the end of line enter
         ignoreFirstLine = true;
         continue;
      }
      type1 >> token;
      type1 >> token;
      type1 >> token;
      type1 >> token;

      out << name << endl;
   		cout << name << endl;
		}
   out.close();
}
Example #4
0
/**
 * \brief     Format the net comment
 * \param[in] fileInput Input file
 * \param[in] m_listComment list of CComments
 *
 * Parses the net comments.
 */
void CComment::Format_netComment(fstream& fileInput, list<CComment>& m_listComment)
{
    char* pcToken, *pcLine;
    char acLine[defCON_MAX_LINE_LEN];
    string comment;

    //Reads all the net comments,parses the comments and stores them to a list.
    while(fileInput.getline(acLine, defCON_MAX_LINE_LEN) && strcmp(acLine, "[END_DESC_NET]")!=0)
    {
        pcLine=acLine;
        m_elementName="";
        pcToken=pcLine;
        comment = pcToken;

        //parses net comment.
        while(strstr(pcToken,"\";") == NULL)
        {
            fileInput.getline(acLine,defCON_MAX_LINE_LEN);
            pcToken = acLine;
            comment += pcToken;
        }

        m_comment= comment;
        //adds the comment to the list.
        m_listComment.push_back(*this);
    }
}
int student::search(char *key)
{
	fd1.close();
	fd1.open("x.txt",ios::in);
	fd1.seekg(0,ios::beg);
	char buf[100],buf1[100],buf2[100];
	while(fd1)
	{
		fd1.getline(buf,100,'\n');
		strcpy(buf1,buf);
		strtok(buf1,"|");
		char *ptr=strtok(NULL,"\0");
		
		if(!strcmp(ptr,"\0")){cout<<"\n\nNo Data";return -1;}
		
		if(strcmp(key,buf1)==0)
		{
			int x=atoi(ptr);
			fd.open("file.txt",ios::in);
			fd.seekg(x,ios::beg);
			fd.getline(buf2,100,'#');
			cout<<"\n\nKey found in search\n"<<buf2;
			fd1.close();
			fd.close();
			return x;
		}
	}
	cout<<"\n\nKey not found";
	return -1;
}
void student::loadlist(char *file1,char *file2)
{
	
	fd1.open(file1,ios::in);
	fd2.open(file2,ios::in);
	
	if(!fd1 || !fd2)
	{
		cout<<"\n\nError in file";
		getch();
		return;
	}
	n1=n2=-1;
	
	while(fd1)
	{
	
		fd1.getline(list1[++n1],20,'\n');
		if(!strcmp(list1[n1],"\0"))
		n1--;
	}
	while(fd2)
	{
	
		fd2.getline(list2[++n2],20,'\n');
		if(!strcmp(list2[n2],"\0"))
		n2--;
	}
	cout<<"\n\nValue of N1:"<<n1<<"\n\nValue of N2:"<<n2<<endl;getch();
}
Example #7
0
void search(){
	//pass
	student std[10];
	char rrn[5];
	char rrn1[10][15];
	int i,j, flag=-1;
	fp.open("student.txt", ios::in);
	cout<<"Enter the rrn number\n";
	cin>>rrn;
	i=0;
	while(!fp.eof()){
		fp.getline(rrn1[i], 4, '|');
		fp.getline(std[i].name, 10, '|');
		fp.getline(std[i].usn, 10, '|');
		fp.getline(std[i].sem, 5, '|');
		fp.getline(std[i].age, 5, '|');
		fp.getline(std[i].branch, 5, '\n');
		i++;
	}
		i--;
		for(j=0; j<i; j++){
			if(strcmp(rrn1[j], rrn) == 0){
				flag = 1;
				cout<<"RRN found";
				cout<<"RRN\tName\tUSN\tSemester\tAge\tBranch\n";
				cout<<rrn<<"\t"<<std[j].name<<"\t"<<std[j].usn<<
		"\t"<<std[j].age<<"\t"<<std[j].sem<<"\t"<<std[j].branch<<"\n";
				break;
			}
		}
		if(flag == -1){
			cout<<"RRN not found\n";
		}
		fp.close();
	}
int ImageType::getPositionAfterHeader(fstream& image)
{
	image.clear();
	image.seekg(0);

	char line[COMMENT_LENGTH];
	char c;
	
	image.getline(line, COMMENT_LENGTH);

	image.get(c);
	while (c == '#') //preskacham komentarite
	{
		image.getline(line, COMMENT_LENGTH);
		image.get(c);
	}
	image.unget();

	int skippedNumber;
	image >> skippedNumber; //preskacham width
	image >> skippedNumber; //preskacham heigth
	image >> skippedNumber; //preskacham maxValue
	
	image.getline(line, COMMENT_LENGTH);
	return image.tellg();
}
void student::search(char *usn)
{

	fd.open("file.txt",ios::in);
	fd1.open("x.txt",ios::in);
	   char buf[100],buf1[100],buf2[100];
	   char buff[100],bufx[100];
	while(fd1)
	{
		fd1.getline(buf,10,'#');
		strcpy(buf1,buf);
		char *ptr=strtok(buf1,"|");
		char *ptr1=strtok(NULL,"#");
		if(strcmp(ptr,usn)==0)
		{
			cout<<"\n\nKey found\n\n";
			int pos=atoi(ptr1);
			fd.seekg(pos-1,ios::beg);
			fd.getline(bufx,100,'#');
			strtok(bufx,"*");
			cout<<bufx;

			fd1.close();fd.close();
			return;
		}
	}
	fd1.close();fd.close();
	cout<<"\n\nNo key";
}
Example #10
0
void writefiles(fstream &input)
{	
	char quit;
	char temp[10];
	int size = getId(input);
	int id;
	Record *rec = (Record*)malloc(sizeof(Record)*(size+1));
	if (size>0)
	{
		input.seekg(0,ios::beg);
		char temp[10];
		for (int j=0; j<size+1; j++)
		{
			input.getline(rec[j].name, 32);
//			cout << rec[j].name << endl;
			input.getline(rec[j].phone, 16);
//			cout << rec[j].phone<<endl;
			input.getline(rec[j].address, 128);
//			cout << rec[j].address<<endl;
			input.getline(temp, 10);
			rec[j].id = atoi(temp);
		}
		size++;
	}
	cin.ignore();
	for (;;)
	{
		cout << "ID >> ";
		cin.getline(temp, 10);
		
		id = atoi(temp);
		cout << id << endl;
		if (checkID(id,rec,size))
		{
			cout << "Record: " << rec[id].name << ", " << rec[id].phone << ", " << rec[id].address << endl;
		}
		else
			cout << "Record: not found!" << endl;


		cout << "Quit(y/n)? >> ";
		
		quit=getchar();
		
 		if (quit == 'y')
		{
			input.close();
			exit(0);
		}
		cin.ignore();
	}
}
void student::search1(char *key)
{
	fd1.close();
	fd1.open("c.txt",ios::in);
	fd1.seekg(0,ios::beg);
	char buf[100],buf1[100],buf2[100];
	while(fd1)
	{
		fd1.getline(buf,100,'\n');
		strcpy(buf1,buf);
		strtok(buf1,"|");
		char *ptr=strtok(NULL,"\0");
		
		if(!strcmp(ptr,"\0")){cout<<"\n\nNo Data";getch();return;}
		
		if(strcmp(key,buf1)==0)
		{
			fd1.close();
			search(ptr);
			return;
		}
	}
	fd1.close();
	cout<<"\n\nKey not found";
	return;
}
void student::search(char *usn1)
{

	fd.open("file.txt",ios::in);
	
	char buf[100],buf1[100],ch;
	int poss=hash(usn1);
	fd.seekg(poss-1,ios::beg);
	while(fd)
	{
		fd.getline(buf,100,'#');
		strcpy(buf1,buf);
		char *ptr=strtok(buf1,"|");
		if(strcmp(ptr,usn1)==0)
		{
			cout<<"\n\nKey found\n\n";
			strtok(buf,"*");
			cout<<buf;

			fd.close();
			return;
		}
		fd.get(ch);
		while((ch=='\0')||(ch=='!'))
		fd.get(ch);

		fd.seekg(-1,ios::cur);

	}
	fd.close();
	cout<<"\n\nNo key";
}
Example #13
0
queue<string> readfile(fstream &fin,parser &SLRparser)
{
	char line[SIZE];
	queue<string> testCases;
    while(fin.getline(line,sizeof(line),'\n')){
		string transfer(line);
		if(!strncmp(line, "#", 1)){
		}
		else if(!strncmp(line, "non-term:", 9)){
			SLRparser.storeNonTerminals(transfer.substr(9));
		}
		else if(!strncmp(line, "term:", 5)){
			SLRparser.storeTerminals(transfer.substr(5));
		}
		else if(!strncmp(line, "prod:", 5)){
			SLRparser.storeProductions(transfer.substr(5));
		}
		else if(!strncmp(line, "start:", 6)){
			SLRparser.storeStartSymbol(transfer.substr(6));
		}
		else{
			testCases.push(transfer);
		}
    }
	return testCases;
}
Example #14
0
void
ScaleBarObject::load(fstream& fin)
{
  clear();

  int len;
  bool done = false;
  char keyword[100];
  while (!done)
    {
      fin.getline(keyword, 100, 0);

      if (strcmp(keyword, "scalebarobjectend") == 0)
	done = true;
      else if (strcmp(keyword, "position") == 0)
	{
	  float x, y;
	  fin.read((char*)&x, sizeof(float));
	  fin.read((char*)&y, sizeof(float));
	  m_pos = QPointF(x,y);
	}
      else if (strcmp(keyword, "voxels") == 0)
	fin.read((char*)&m_voxels, sizeof(float));
      else if (strcmp(keyword, "type") == 0)
	fin.read((char*)&m_type, sizeof(bool));
      else if (strcmp(keyword, "textpos") == 0)
	fin.read((char*)&m_textpos, sizeof(bool));
    }
}
Example #15
0
void initialization(void) { 
   nextnotetime = t_time;
   data.setSize(0);
   #ifndef OLDCPP
      input.open("file", ios::in);
   #else
      input.open("file", ios::in | ios::nocreate);
   #endif
   if (!input.is_open()) {
      cout << "Error: cannot open file" << endl;
      exit(1); 
   }
   input.getline(buffer, 1024, '\n');
   while (!input.eof() && !isdigit(buffer[0])) {
      input.getline(buffer, 1024, '\n');
   }
}
Example #16
0
string load_inputfile(fstream &f){
	string tmp = "";
	char buffer[1024];
	while(f.eof() != true) {
		f.getline(buffer,1024);
		tmp += remove_white_spaces(buffer);
	} 
	return tmp;
}
Example #17
0
int InputPar(fstream &in,double &from,double &min,double &max,
                                                 double &stp,char *write)
  {
//   fstream in(name,ios::in);
   int ret=0;
   in>>write>>from>>write>>min>>write>>max>>write>>stp;in.getline(write,255);
   in>>write>>ret>>write;
   return ret;
  };
Example #18
0
void
VolumeFileManager::load(fstream &fin)
{
  reset();

  bool done = false;
  char keyword[100];

  while (!done)
    {
      fin.getline(keyword, 100, 0);

      if (strcmp(keyword, "volumefilemanagerend") == 0)
	done = true;
      else if (strcmp(keyword, "basefilename") == 0)
	{
	  char *str;
	  int len;
	  fin.read((char*)&len, sizeof(int));
	  str = new char[len];
	  fin.read((char*)str, len*sizeof(char));
	  m_baseFilename = QString(str);
	  delete [] str;
	}
      else if (strcmp(keyword, "filenames") == 0)
	{
	  int nfls;
	  fin.read((char*)&nfls, sizeof(int));
	  for (int i=0; i<nfls; i++)
	    {
	      char *str;
	      int len;
	      fin.read((char*)&len, sizeof(int));
	      str = new char[len];
	      fin.read((char*)str, len*sizeof(char));
	      m_filenames << QString(str);
	      delete [] str;
	    }
	}
      else if (strcmp(keyword, "voxeltype") == 0)
	{
	  int vt;
	  fin.read((char*)&vt, sizeof(int));
	  setVoxelType(vt);
	}
      else if (strcmp(keyword, "header") == 0)
	fin.read((char*)&m_header, sizeof(int));
      else if (strcmp(keyword, "slabsize") == 0)
	fin.read((char*)&m_slabSize, sizeof(int));
      else if (strcmp(keyword, "depth") == 0)
	fin.read((char*)&m_depth, sizeof(int));
      else if (strcmp(keyword, "width") == 0)
	fin.read((char*)&m_width, sizeof(int));
      else if (strcmp(keyword, "height") == 0)
	fin.read((char*)&m_height, sizeof(int));
    }
}
Example #19
0
/**
 * \brief     Format signal comments
 * \param[in] fileInput Input file
 * \param[in] m_listComment List of CComments
 *
 * Parses the signal comments.
 */
void CComment::Format_sigComment(fstream& fileInput, list<CComment>& m_listComment)
{
    char* pcToken;
    char* pcNextToken;
    char* pcLine;
    char acLine[defCON_MAX_LINE_LEN];
    string comment;

    //Reads all the signal comments,parses the comments and stores them to a list.
    while(fileInput.getline(acLine, defCON_MAX_LINE_LEN) && strcmp(acLine, "[END_DESC_SIG]")!=0)
    {
        pcLine=acLine;
        //get the mesgid.
        pcToken = strtok_s(pcLine, " ", &pcNextToken);
        m_msgID=unsigned int(atoi(pcToken));
        //get the mesg type and validates.
        pcToken = strtok_s(NULL, " ", &pcNextToken);
        m_msgType=*pcToken;

        if(m_msgType =='X')
        {
            m_msgID -=2147483648;
        }

        //get signal name.
        pcToken = strtok_s(NULL, " ", &pcNextToken);
        m_elementName=pcToken;
        //  m_elementName = m_elementName.Left(defCON_MAX_MSGN_LEN);
        //get comment.
        pcToken = strtok_s(NULL, "", &pcNextToken);
        comment = pcToken;

        while(strstr(pcToken,"\";") == NULL)
        {
            fileInput.getline(acLine,defCON_MAX_LINE_LEN);
            pcToken = acLine;
            comment += pcToken;
        }

        m_comment= comment;
        //adds the comment to list.
        m_listComment.push_back(*this);
    }
}
void ImageType::skipHeaderInPBM(fstream& image)
{
	char line[COMMENT_LENGTH];
	char c;
	image.getline(line, COMMENT_LENGTH);

	image.get(c);
	while (c == '#') //preskacham komentarite
	{
		image.getline(line, COMMENT_LENGTH);
		image.get(c);
	}
	image.unget();

	int skippedNumber;
	image >> skippedNumber; //preskacham width
	image >> skippedNumber; //preskacham heigth
	//pri pixelBitmap nqma maxValue
}
void TSensorView::ReadLayout(fstream& f,int nVersion)
{
  char buf[25];
  TDataView::ReadLayout(f,nVersion);
  f >> m_nType >> m_bGrid;
// f >> m_dBright; work around a bug with Win95
  f >> ws;
  f.getline(buf,sizeof(buf));
  m_dBright = atof(buf);
}
Example #22
0
void
GiLightObjectInfo::load(fstream &fin)
{
  bool done = false;
  char keyword[100];
  float f[3];

  lod = 1;
  smooth = 1;
  points.clear();

  while(!done)
    { 
      fin.getline(keyword, 100, 0);
      if (strcmp(keyword, "end") == 0)
	done = true;
      else if (strcmp(keyword, "points") == 0)
	{
	  int npts = 0;
	  fin.read((char*)&npts, sizeof(int));
	  for(int i=0; i<npts; i++)
	    {
	      fin.read((char*)&f, 3*sizeof(float));
	      points << Vec(f[0], f[1], f[2]);
	    }
	}
      else if (strcmp(keyword, "allowinterpolation") == 0)
	fin.read((char*)&allowInterpolation, sizeof(bool));
      else if (strcmp(keyword, "doshadows") == 0)
	fin.read((char*)&doShadows, sizeof(bool));
      else if (strcmp(keyword, "show") == 0)
	fin.read((char*)&show, sizeof(bool));
      else if (strcmp(keyword, "lighttype") == 0)
	fin.read((char*)&lightType, sizeof(int));
      else if (strcmp(keyword, "rad") == 0)
	fin.read((char*)&rad, sizeof(float));
      else if (strcmp(keyword, "decay") == 0)
	fin.read((char*)&decay, sizeof(float));
      else if (strcmp(keyword, "angle") == 0)
	fin.read((char*)&angle, sizeof(float));
      else if (strcmp(keyword, "color") == 0)
	{
	  fin.read((char*)&f, 3*sizeof(float));
	  color = Vec(f[0], f[1], f[2]);
	}
      else if (strcmp(keyword, "opacity") == 0)
	fin.read((char*)&opacity, sizeof(float));
      else if (strcmp(keyword, "segments") == 0)
	fin.read((char*)&segments, sizeof(int));
      else if (strcmp(keyword, "lod") == 0)
	fin.read((char*)&lod, sizeof(int));
      else if (strcmp(keyword, "smooth") == 0)
	fin.read((char*)&smooth, sizeof(int));
    }
}
Example #23
0
inline void getlined(fstream &stream, vector<double> &result) {
    char str[512];
    result.clear();
    stream.getline(str, 512);
    //split(result, str);

	vector<string> tokens = split(str, ' ');
	for (auto &token : tokens) {
		result.push_back(std::stod(token));
	}
}
void student::unpack()
{
	fd.open("file.txt",ios::in);
	char buf[100];
	while(fd)
	{
		fd.getline(buf,100,'#');
		cout<<"\n\n"<<buf;
	}
	fd.close();
}
Example #25
0
void display(){
	//pass
	student s;
	char rrn[5];
	int i;

	fp.open("student.txt", ios::in);
	if(!fp){
		cout<<"Unable to open \n";
	}

	while(!fp.eof()){
		fp.getline(rrn , 4, '|');
		fp.getline(s.name , 10, '|');
		fp.getline(s.usn , 10, '|');
		fp.getline(s.sem , 5, '|');
		fp.getline(s.age , 5, '|');
		fp.getline(s.branch, 5, '\n');

		cout<<rrn<<"\t"<<s.name<<"\t"<<s.usn<<"\t"<<s.sem<<"\t"<<s.age<<"\t"<<s.branch<<"\n";
	}
	fp.close();
}
Example #26
0
int playline(void) {
   data.setSize(0);
   int datum;
   uchar uchardatum;

cout << buffer << endl;

   char* dataz = strtok(buffer, "\t ");
   dataz = strtok(NULL, "\t ");
   while ((dataz != NULL && dataz[0] != ';') && (isdigit(dataz[0]))) {
      if (dataz[0] == '0' && dataz[1] == 'x') {
         sscanf(dataz, "%x", &datum); // %D doesn't work in Visual C++ 6.0
      } else {
         sscanf(dataz, "%D", &datum);
      }
      uchardatum = (uchar)datum;
      data.append(uchardatum); 
      dataz = strtok(NULL, "\t ");
   }
   
   synth.rawsend(data.getBase(), data.getSize());

   input.getline(buffer, 1024, '\n');
   while (!input.eof() && !isdigit(buffer[0])) {
      input.getline(buffer, 1024, '\n');
   }

   if (input.eof()) {
      cout << "End of file" << endl;
      exit(0);
   }

   int deltatime;
   sscanf(buffer, "%d", &deltatime);

   return deltatime;
}
Example #27
0
int verifyRecords(fstream& color, char a[100], char b[100], int t, int minPace, int maxPace){
	int errors=0;
	// will return extra repeated t value but the repeated value should still be in range
	while (!color.eof()){
		color.getline(a, 100,' ');
		color.getline(b, 100,' ');
		color >> t;
		//takes care of \n character
		color.get();
		if (!(t>=minPace&& t<=maxPace)){
			cout <<"sorting error." << endl;
			errors++;
		}
		return errors;
	}
void student::del(char *key)
{
	int x=search(key);
	if(x==-1)
	return;
	    char buf[100],buf1[100],buf2[100],bufx[100];
	fd.close();
	fd.open("x.txt",ios::in);
	fd.seekg(0,ios::beg);
	while(fd)
	{
		fd.getline(buf,100,'\n');
		strcpy(buf1,buf);
		strtok(buf1,"|");
		char *ptr=strtok(NULL,"\n");
		strcpy(bufx,ptr);
		
		if(!strcmp(buf1,"\0")){cout<<"\n\nNo data error";getch();return;}
		
		if(strcmp(key,buf1)==0)
		{
			cout<<"\n\nKey found in del"<<buf;
			strcat(buf,"\n");
			int y=strlen(buf);
			int tel=fd.tellg();
			fd.close();
			fd.open("x.txt",ios::out|ios::in);
			fd.seekp(tel,ios::beg);
			fd.seekp(-(y+1),ios::cur);
			fd<<"*";
			fd.close();

			int q=atoi(ptr);
			fd.open("file.txt",ios::out|ios::in);
			fd.seekp(q,ios::beg);
			fd<<"*";
			fd.close();
			cout<<"\n\nKey deleted";

			return;
		}
	}

		fd.close();
		cout<<"\n\nCouldnt del";
		return;
}
Example #29
0
/* Given:   InFile      Text file stream already opened for input.
            MoreData    Indicates if there is more data from InFile to place into Buffer.
                        At the very least this indicates if there is an unused item in NextWord.
            NextWord    If MoreData is true, then NextWord contains an unprocessed word from
                        InFile that has yet to be placed into Buffer.
   Task:    If MoreData is true, this function places as much data as possible from InFile into
            Buffer.  This data includes NextWord and then as much new data as possible from InFile.
            The Buffer will be filled if there is enough data to do so.
   Return:  In the function name is returned the number of words placed into Buffer.
            InFile      The modified file stream.
            Buffer      Contains the data that has been copied in from InFile.
            MoreData    Indicates if NextWord contains a word that has not yet been placed into Buffer.
            NextWord    If MoreData is true, this contains the next word from InFile that has
                        not yet been placed into Buffer.
*/
int FillBuffer(fstream & InFile, BufType Buffer, bool & MoreData, StringType NextWord)
   {
   int k = 0;

   while (MoreData && (k < BufSize))
      {
      strcpy(Buffer[k], NextWord);
      InFile.getline(NextWord, MaxString);
      if (InFile.fail())
         MoreData = false;
      else
         MoreData = true;
      k++;
      }

   return k;
   }
void student::sort(int mode)
{
	char buf[100][100];
	int i=0,l=0;
	
	if(mode==1)
		fd1.open("x.txt",ios::in|ios::out);
	else
		fd1.open("c.txt",ios::in|ios::out);
	
	
	while(fd1)
	{
		fd1.getline(buf[i],100,'\n');
		if(buf[i]==NULL)continue;
		if(fd1)
		i++;
	}

	for(int x=0;x<i;x++)
	{
		for(int y=x+1;y<i;y++)
		{
			if(strcmp(buf[x],buf[y])>0)
			{
				char temp[100];
				strcpy(temp,buf[x]);
				strcpy(buf[x],buf[y]);
				strcpy(buf[y],temp);
			}
		}
	}

	fd1.close();
	if(mode==1)
	{
		remove("x.txt");
		fd1.open("x.txt",ios::out);
	}
	
	if(mode==2)
	{	
		remove("c.txt");
		fd1.open("c.txt",ios::out);
	}
	
	while(l<i)
	fd1<<buf[l++]<<endl;
	fd1.close();

}