ENSDF++ 1.1
An easy, fast and simple way to run querys towards the ENSDF database, written in C++.
Unique.cpp
Go to the documentation of this file.
00001 #include "Unique.h"
00002 #include <iostream>
00003 
00004 bool uniqueCompare(string first, string second)
00005 {
00006   if(first.length()!=second.length())
00007     return false;
00008   for(unsigned int i = 0; i<first.length(); i++)
00009     {
00010       if(first[i]!=second[i])
00011         return false;
00012     }
00013   return true;
00014 }
00015 
00016 bool uniqueSort(string first, string second)
00017 {
00018   for(unsigned int i = 0; i<first.length() && i<second.length(); i++)
00019     {
00020       if(first[i]<second[i])
00021         return true;
00022       if(first[i]>second[i])
00023         return false;
00024     }
00025   return first.length()<second.length();
00026 }
00027 
00028 int main(int argc, char* argv[])
00029 {
00030   if(argc!=3)
00031     {
00032       fprintf(stderr,"Usage: %s inputfile outputfile\n",argv[0]);
00033       return 0;
00034     }
00035   FILE * myFile;
00036   myFile = fopen(argv[1],"r");
00037   if(myFile==NULL)
00038     perror("File 1 could not be opened.\n");
00039   char line[100];
00040   list<string> myList;
00041   while (fgets(line,100,myFile)!=NULL)
00042     {
00043       string myString(line);
00044       myList.push_back(myString);
00045     }
00046   pclose(myFile);
00047   myList.sort(uniqueSort);
00048   myList.unique(uniqueCompare);
00049   myFile = fopen(argv[2],"w");
00050   if(myFile==NULL)
00051     perror("File 2 could not be opened.\n");
00052   for(list<string>::iterator it = myList.begin(); it!=myList.end(); it++)
00053     {
00054       fprintf(myFile, "%s", (*it).c_str());
00055     }
00056   pclose(myFile);
00057   return 0;
00058 }
 All Classes Files Functions Variables Enumerations Enumerator Defines

Back to the main page of the Precalibrated Ion Beam Identification Detector project

Created by Rikard Lundmark