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"; }
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(); }
int ReadIndex( fstream &File ) { BYTE b0, b1, b2, b3, b4; int result = 0; b0 = File.get(); if (b0 & 0x40) { b1 = File.get(); if (b1 & 0x80) { b2 = File.get(); if (b2 & 0x80) { b3 = File.get(); if (b3 & 0x80) { b4 = File.get(); result = b4; } result = (result << 7) + (b3 & 0x7F); } result = (result << 7) + (b2 & 0x7F); } result = (result << 7) + (b1 & 0x7F); } result = (result << 6) + (b0 & 0x3F); if (b0 & 0x80) result = -result; return result; }
//特征词典生成 void termDictionary::createDictionary() { fin.open("文档集.txt", ios::in); if (!fin) { cout << "打不开文件--文档集.txt!\n"; exit(0); } char ch, str1[10], str2[5]; char type[50][5] = {"a", "ad", "Ag", "b", "c", "d", "e", "m", "ms", "o", "p", "q", "u", "w", "y", "z", ""}; //不纳入特征词典的词性 int id = 0, flag1 = 0, flag2 = 0; ch = fin.get(); while (!fin.eof()) { if (ch == '\n') { ch = fin.get(); continue; } strcpy(str1, getTerm(ch)); for (int i = 0; i < dictionarySize; i++) { //提取特征词后,扫描特征词典,若词典中存在此特征词,则置标志为1 if (!strcmp(TD.termArray[i].t, str1)) { flag1 = 1; break; } } ch = fin.get(); strcpy(str2, getType(ch)); for (int i = 0; i < 50; i++) { //提取特征词词性以后,扫描不纳入特征词典的词性数组,若存在词性,则置标志位为1 if (!strcmp(str2, type[i])) { flag2 = 1; break; } } if (!flag1 && !flag2) { //若两个标志位均未0,则把特征词id,特征词,词性,插入特征词典 TD.termArray[dictionarySize].termID = id; strcpy(TD.termArray[dictionarySize].t, str1); strcpy(TD.termArray[dictionarySize].type, str2); dictionarySize++; id++; } flag1 = 0; flag2 = 0; ch = fin.get(); ch = fin.get(); } fin.close(); fout.open("特征词典.txt", ios::out); if (!fout) { cout << "打不开特征词典.txt!\n"; exit(0); } for (int i = 0; i < dictionarySize; i++) { //把特征词典输出到文件-特征词典.txt fout << TD.termArray[i].termID << " " << termArray[i].t << " " << TD.termArray[i].type << endl; } fin.close(); }
ulong getLong() { // get little-endian 4-byte value from file, compose along portably ulong ip = 0; char ic = 0; unsigned char uc = ic; inf.get(ic); uc = ic; ip = uc; inf.get(ic); uc = ic; ip |=((ulong)uc << 8); inf.get(ic); uc = ic; ip |=((ulong)uc << 16); inf.get(ic); uc = ic; ip |=((ulong)uc << 24); return ip; }
void typeon() { char str[1]; str[1]='\0'; file.get(str[0]); while(!file.eof()) { if(str[0]=='*') break; if(str[0]=='\n') { y+=20; x=10; } outtextxy(x,y,str); delay(50); file.get(str[0]); x+=8; }}
//<<<<<<<<<<<<<<<<<<<< getLong >>>>>>>>>>>>>>>>>>> ulong getLong() //helper function { //BMP format uses little-endian integer types // get a 4-byte integer stored in little-endian form ulong ip = 0; char ic = 0; unsigned char uc = ic; inf.get(ic); uc = ic; ip = uc; inf.get(ic); uc = ic; ip |=((ulong)uc << 8); inf.get(ic); uc = ic; ip |=((ulong)uc << 16); inf.get(ic); uc = ic; ip |=((ulong)uc << 24); return ip; }
int PixelMap:: readBMPFile(string fname) { // Read into memory an Pixel image from an uncompressed BMP file. // return 0 on failure, 1 on success inf.open(fname.c_str(), ios::in|ios::binary); //must read raw binary char's. if(!inf){ cout << " can't open file: " << fname << endl; return 0;} int k, row, col, numPadBytes, nBytesInRow; // read header information char ch1, ch2; inf.get(ch1); inf.get(ch2); // type is always 'BM' //cout << "file type = " << ch1 << ch2 << endl; ulong fileSize = getLong(); ushort reserved1 = getShort(); // always 0 ushort reserved2= getShort(); // always 0 ulong offBits = getLong(); // offset to image - unreliable ulong headerSize = getLong(); // always 40 ulong numCols = getLong(); // number of columns in image ulong numRows = getLong(); // number of rows in image ushort planes= getShort(); // always 1 ushort bitsPerPix = getShort(); // 8 or 24;only 24 bit case done ulong compression = getLong(); // must be 0 for umcompressed ulong imageSize = getLong(); // total bytes in image ulong xPels = getLong(); // always 0 ulong yPels = getLong(); // always 0 ulong numLUTentries = getLong(); // 256 for 8 bit, otherwise 0 ulong impColors = getLong(); // always 0 if(bitsPerPix != 24) {cout << "not a 24 bit/pixelimage!\n"; inf.close(); return 0;}; // error! // in BMP file, pad bytes inserted at end of each row so total number is a mult. of 4 nBytesInRow = ((3 * numCols + 3)/4) * 4; // round up 3*numCols to next mult. of 4 numPadBytes = nBytesInRow - 3 * numCols; // need this many m_rows = numRows; // set class's data members m_cols = numCols; cout << "numRows,numCols = " << numRows << "," << numCols << endl; cout.flush(); m_pixel = new Pixel[m_rows * m_cols]; //space for array in memory if(!m_pixel) return 0; // out of memory! long count = 0; char dum,r,g,b; for(row = 0; row < m_rows; row++) // read pixel values { for(col = 0; col < m_cols; col++) { inf.get(b); inf.get(g); inf.get(r); // funny color order in BMP file m_pixel[count].set_r(r); m_pixel[count].set_g(g); m_pixel[count++].set_b(b); } for(k = 0; k < numPadBytes ; k++) //skip over padding bytes at row's end inf >> dum; } inf.close(); return 1; // success }
void readString(MyString &string, char limit, fstream &fin) { char ch; //string.first = createNewSymbol(ch); MySymbol **tmp = &(string.first); //string.length++; fin.get(ch); while (ch != limit) { *tmp = createNewSymbol(ch); tmp = &((*tmp)->next); string.length++; fin.get(ch); } }
/* this function extracts the data received by the input file. it does it by ignoring all characters that are not numbers and also keeps count of the number of rows and columns per input matrix. */ void getData(fstream &input) { string garbage, add; char value; int temp[2] = {0,0},i = 0, row[2] = {0,0}, column[2] = {0,0}; /* extract data from the input file and store the values in a vector, while keeping count on a series of int arrays */ while (!input.eof()) { input.get(value); if (value != ' ' && value != '*' && value != '\n' && value != '\t') { add = add+value; temp[i]++; } else if (value == '\n' && !input.eof()) { row[i]++; column[i] = temp[i]; temp[i] = 0; } else if (value == '*') { getline(input,garbage); ++i; } } row[1]++; //error correcting bug for compatibilty /* checks for matrix compatibility */ if (column[0] != row[1]) { cout << "invalid matrices!" <<endl; exit(0); } /* matrix creations and memory allocations */ matrices.matrix1 = makeArray(row[0], column[0]); matrices.matrix2 = makeArray(column[1], row[1]); //fills the info extracted from in input matrix in the form of a string fillArray(matrices.matrix1, row[0], column[0], add, 0); fillArray2(matrices.matrix2, row[1], column[1], add, row[0]*column[0]); processCall(row[0], column[0], column[1], row[1]); }
// return nabber of filled objects int fillFromFile(fstream & fin, employee ** pArr, int nSize) { int id; int i = 0; while (i < nSize && fin.good() && fin.peek() != EOF) { fin >> id; switch(id) { case abstr_emp::EMPLOYEE: pArr[i] = new employee; break; case abstr_emp::MANAGER: pArr[i] = new manager; break; case abstr_emp::FINK: pArr[i] = new fink; break; case abstr_emp::HIGHFINK: pArr[i] = new highfink; break; default: throw "Error while reading file"; } fin.get(); // '\n' pArr[i]->GetAll(fin); i++; } fin.clear(); return i; }
void centro(char*testo[],int righe,int maxlungriga) { int i=0,j=0,d=0; char c; char parola[righe][maxlungriga]; //utilizzo la matrice per scrivere il file di testo input.open(testo[1],ios::in); while(input.get(c)) { parola[j][i]=c; //inserisce la parola letta nella matrice i++; if (c=='\n') // quando arriva al carattere "invio" { d=maxlungriga-i; // calcola la differenza tra la lunghezza base e la parola letta if(d==0) // questo è il caso dove hai la parola massima (opzionale) { for (int k=0;k<i;k++) cout << parola[j][k]; } else { //metto metà spazi a detsra e metà a sinistra for(int g=0;g<=(d/2);g++) cout << " "; for (int k=0;k<i;k++) cout << parola[j][k]; for(int e=0;e<=(d/2);e++) cout << " "; } //cout << endl; j++;i=0;d=0; } } input.close(); }
/*------------------------------------------------------------------------------------------------------------------ -- FUNCTION: readFile -- -- DATE: November 20, 2013 -- -- REVISIONS: December 1, 2013 Added stats tracking. -- -- DESIGNER: Jordan Marling -- -- PROGRAMMER: Jordan Marling -- -- INTERFACE: void readFile(fstream &is) -- is: the inputstream to the data that is being sent. -- -- RETURNS: void -- -- NOTES: This function reads in data from an input stream and packetizes it. -- ----------------------------------------------------------------------------------------------------------------------*/ void readFile(fstream &is) { char data[DATA_SIZE]; int tmp; int count = 0; send_control = SOT1; while ((tmp = is.get()) >= 0) { data[count++] = (char)tmp; if (count >= DATA_SIZE) { packetize(data); count = 0; } } // stats.totalPadding_ += DATA_SIZE - count; HandleStats(section, stats, 9, DATA_SIZE - count); for(;count < DATA_SIZE; count++) { data[count] = (char)0; } packetize(data); }
ushort getShort() {// read a short in little-endian form char ic; ushort ip; inf.get(ic); ip = ic; //first byte is little one inf.get(ic); ip |= ((ushort)ic << 8); // or in high order byte return ip; }
void filAray(char a[][COLS],int r,int c,fstream &file){ //fill array for(int rowPos=0;rowPos<r;rowPos++){ for(int colPos=0;colPos<c;colPos++){ a[rowPos][colPos]=file.get();//grabs char from file } } }
//<<<<<<<<<<<<<<<<<<<<< getShort >>>>>>>>>>>>>>>>>>>> ushort getShort() //helper function { //BMP format uses little-endian integer types // get a 2-byte integer stored in little-endian form char ic; ushort ip; inf.get(ic); ip = ic; //first byte is little one inf.get(ic); ip |= ((ushort)ic << 8); // or in high order byte return ip; }
void Citire() { /*f.open(inf,ios::in); f.get(sir,Max); f.close();*/ f.open(inf,ios::in); f.get(cp,Max); f.close(); }
void makeArray(int tab[50][100]) { int x = 0; int y = 0; char c = ' '; while (y < 100) { while (x<50) { f.get(c); tab[x][y] = int(c) - '0'; ++x; }; f.get(c); x = 0; ++y; }; f.close(); };
void readWord(MyString &word, Status isCapitalEqualSmall, fstream &fin) { char symbol; fin.get(symbol); word.first = createNewSymbol(symbol); MySymbol *tmp = word.first; word.length++; fin.get(symbol); while ((symbol >= 'a' && symbol <= 'z') || (symbol >= 'A' && symbol <= 'Z')) { if (isCapitalEqualSmall == no) symbol = (char)tolower(symbol); tmp->next = createNewSymbol(symbol); tmp = tmp->next; word.length++; fin.get(symbol); } }
void sinistra(char *testo[],int righe) { // è il classico modo di scrivere input.open(testo[1],ios::in); char c; while(input.get(c)) // prende il carattere... { cout << c; // e lo scrive } input.close(); }
void File::partition (int low, int high, int& pivotLoc) { char rec[recordLen+1], pivot[recordLen+1]; register int i, lastSmall; swap(pointers[low],pointers[(low+high)/2]); outfile.clear(); outfile.seekg(pointers[low]*recordLen,ios::beg); outfile.get(pivot,recordLen+1); for (lastSmall = low, i = low+1; i <= high; i++) { outfile.clear(); outfile.seekg(pointers[i]*recordLen,ios::beg); outfile.get(rec,recordLen+1); if (strcmp(rec,pivot) < 0) { lastSmall++; swap(pointers[lastSmall],pointers[i]); } } swap(pointers[low],pointers[lastSmall]); pivotLoc = lastSmall; }
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 skip_space(fstream& fileStream) { // skip white space in the headers or pnm files char c; do { c = fileStream.get(); } while (c == '\n' || c == ' ' || c == '\t' || c == '\r'); fileStream.unget(); }
void File::insertion(char line[]) { int address = hash(line), counter = 0; char name[recordLen+1]; bool done = false, inserted = false; outfile.clear(); outfile.seekg(address,ios::beg); while (!done && outfile.get(name,recordLen+1)) { if (name[0] == empty || name[0] == delMarker) { outfile.clear(); outfile.seekg(address+counter*recordLen,ios::beg); outfile << line << setw(strlen(line)-recordLen); done = inserted = true; } else if (!strcmp(name,line)) { cout << line << " is already in the file\n"; return; } else counter++; if (counter == bucketSize) done = true; else outfile.seekg(address+counter*recordLen,ios::beg); } if (!inserted) { done = false; counter = 0; overflow.clear(); overflow.seekg(0,ios::beg); while (!done && overflow.get(name,recordLen+1)) { if (name[0] == delMarker) done = true; else if (!strcmp(name,line)) { cout << line << " is already in the file\n"; return; } else counter++; } overflow.clear(); if (done) overflow.seekg(counter*recordLen,ios::beg); else overflow.seekg(0,ios::end); overflow << line << setw(strlen(line)-recordLen); } }
string FM_database::get_string( fstream& fio , index_t len ) { string s = ""; for (int i=0; i<len; i++) { char ch; fio.get( ch ); s+=ch; } return s; }
//子操作,定义为外部函数 char *getTerm(char ch) { //提取term的内容 int i = 0; char str[10], *p; while (ch != '/') { //把单个字符存入数组,直到碰到'/' str[i++] = ch; ch = fin.get(); } str[i] = '\0'; p = str; return p; }
char *getType(char ch) { //提取term的词性 int i = 0; char str[5], *p; while (ch != EOF && ch != ' ') { //把单个字符存入数组,直到碰到' ' str[i++] = ch; ch = fin.get(); } str[i] = '\0'; p = str; return p; }
void File::operator- () { char c; // f2 will be this fp.open(fn,ios::in); int temp = fp.rdstate(); cout <<endl<< "after opening in read mode ; " <<temp; if(temp != 0) { fp.clear(); } fp.close(); fp.open (fn, ios::in | ios::out); int t = fp.rdstate (); cout << "\n In oprt - t=" << t; if (t == 0) { fp.seekg (0, ios::beg); while (1) { fp.get (c); cout <<endl<< "c = " << c; if (fp.eof ()) break; if (!fp.eof ()) { if (c >= 'A' && c <= 'Z') { /* AbCFdEGGD */ c += 32; fp.seekg (-1, ios::cur); fp.put (c); int temp = fp.rdstate(); cout << endl<<"after putting '" << c << "' into file : "<<temp; getchar(); } else if (c >= 'a' && c <= 'z') { c -= 32; fp.seekg (-1, ios::cur); fp.put (c); int temp = fp.rdstate(); cout << endl<<"after putting '" << c << "' into file : "<<temp; getchar(); } } } fp.close (); } }
void File::sortFile() { char rec[recordLen+1]; QSort(1,pointers[0]); // pointers[0] contains the # of elements; // put data from outfile in sorted order in file sorted: for (int i = 1; i <= pointers[0]; i++) { outfile.clear(); outfile.seekg(pointers[i]*recordLen,ios::beg); outfile.get(rec,recordLen+1); sorted << rec << setw(strlen(rec)-recordLen); } }
string JSONDataItem:: readQuotedString(fstream &stream) { char cc; string append; stream >> cc; while( cc != '"') { if(cc == '\\') { append += cc; stream.get(cc); append += cc; } else append += cc; stream.get(cc); } return append; }