bool StreamBuffer::write(const void* buffer, int size){ if(buffer==NULL){ return false; cout<<"input buffer void pointer"<<endl; } if(size>buffersize){ return false; cout<<"buffer too small for input buffer"<<endl; } if(offset+size>buffersize){ //cout<<"2"<<endl; cout<<"Auto save file, reset offset"<<endl; savetofile(); // delete[] mybuffer; // mybuffer = new char[buffersize]; cout<<"Auto save file, reset offset"<<endl; offset = 0; memcpy(mybuffer+offset, buffer, size); offset = offset + size; return true; } if(offset+size<buffersize){ //cout<<"1"<<endl; //cout<<"offset changing:"<<offset<<" "<<buffersize<<endl; memcpy(mybuffer+offset, buffer, size); offset = offset+size; return true; } if(offset+size==buffersize){ //cout<<"3"<<endl; //cout<<"offset changing:"<<offset<<" "<<buffersize<<endl; memcpy(mybuffer+offset, buffer, size); offset = offset+size; savetofile(); // delete[] mybuffer; // mybuffer = new char[buffersize]; offset = 0; return true; } return false; }
void main (void){ char again; //variable to get input for continuing program after run starbar(); cout << "Welcome to the GPA Calculator." << endl << "This program will calculate the GPA" << endl << "of a student for each semester, and" << endl << "the entire year, as well as determine" << endl << "whether the student achieved Dean's list" << endl << "or Dean's Honor List." << endl; starbar(); system("pause"); do{ cout << "How many students would you like to input?(max. " << MaxStudents << ")"; cin >> numstudents; } while(numstudents < 0 || numstudents > MaxStudents); for(y=0; y < numstudents; y++){ input(); verify(); calc(); savetofile(); } cout << "Thank you for using this program." << endl; system("pause"); }
void extract(struct chmFile *c, struct chmUnitInfo *ui, long extractwithoutpath) { char target[CHM_MAX_PATHLEN*2+1]; wchar_t temp[CHM_MAX_PATHLEN+1]; decode_UTF8(temp,ui->path); #ifndef UNIX WideCharToMultiByte(CP_OEMCP,0,temp,-1,target,sizeof(target),NULL,NULL); #else wcstombs(target, temp, sizeof(target)); #endif printf("Extracting %s ",target); if (savetofile(c, ui, extractwithoutpath)) { printf("Error\n"); error=1; //return CHM_ENUMERATOR_FAILURE; } else printf("OK\n"); }
void TUserList::savetofile() { savetofile(filename); }
int main(int argc, char *argv[]) { double t_begin, t_end; int i; int width = WIDTH; int height = HEIGHT; REAL *fout, *fin, *ftmp; REAL *fa = (REAL *)malloc(sizeof(REAL)*WIDTHP*HEIGHT); REAL *fb = (REAL *)malloc(sizeof(REAL)*WIDTHP*HEIGHT); REAL time = 0.0; int count = 1000; REAL stendiag, stennext, stenctr; fin = fa; fout = fb; printf("Initializing..%d Threads, %d x %d, PAD=%d..\n\n", omp_get_num_threads(),WIDTH, HEIGHT, WIDTHP); initbuf(fin, width, height); initbuf(fout, width, height); #if DBG dbgprint(fin, WIDTHP, height); #endif #if SAVEFILES savetofile("stencil9pt_init.dat", fin, WIDTHP, HEIGHT); #endif // stencil params: slowly blurring... stendiag = 0.00125; stennext = 0.00125; stenctr = 0.99; printf("Running stencil kernel %d times\n", count); t_begin = dtime(); stencil9pt_base(fin, fout, width, height, stenctr, stennext, stendiag,count); t_end = dtime(); #if DBG dbgprint(fout, WIDTHP, height); #endif #if SAVEFILES savetofile("stencil9pt_result.dat",fb, WIDTHP, HEIGHT); #endif double elapsed_time = t_end - t_begin; REAL mflops = (width*height)*17.0*count/elapsed_time * 1.0e-06; printf("Elapsed time : %.3f (s)\n", elapsed_time); printf("FLOPS : %.3f (MFlops)\n", mflops); free(fa); free(fb); return 0; }