int main() { if (0 == data_input("input.txt")) { result = unique_char(str_src); if (0 == data_output("output.txt")) { return 0; } } return 1; }
int main() { if (0 == data_input("input.txt")) { result = plus(num_a, num_b); if (0 == data_output("output.txt")) { return 0; } } return 1; }
int main() { if (0 == data_input("input.txt")) { selection_sort(data, length); if (0 == data_output("output.txt")) { return 0; } } return 1; }
int main() { if (0 == data_input("input.txt")) { shuffle(data, length); quick_sort(data, 0, length - 1); if (0 == data_output("output.txt")) { return 0; } } return 1; }
/*main需要另外调整*/ int main(char argc,char *argv[]) { int len; int *res=data_input(10230023,&len); int i=0; printf("len:%d\n",len); for(i=0;i<len;i++) { printf("%d now %d\n",i,res[i]); } getchar(); int *output=(int *)malloc(sizeof(int)*len); product(res,output,len); int fn=data_output(output,len); printf("%d\n",fn); free(res); free(output); getchar(); }
bool NPushReportSpeed::load_from_dir(QString &dirName) { QString data_in_filename = (dirName + FSC_FSYS_SLASH) + "Speed.xml"; QFile data_input(data_in_filename); data_input.open(QFile::ReadOnly | QFile::Text); QXmlStreamReader xml; xml.setDevice(&data_input); if(xml.readNextStartElement()) { if(xml.name() != "SpeedReport") { qDebug() << "Invalid file format"; return false; } } else { qDebug() << "Could not read first start Element"; return false; } do { while(xml.readNextStartElement()) { if(xml.name() == "stats") { Speed_max = xml.attributes().value("max").toString().toDouble(); Speed_avg = xml.attributes().value("avg").toString().toDouble(); } else if(xml.name() == "graph") { read_points_from_xml(xml); } else { xml.skipCurrentElement(); } } } while(xml.name() != "SpeedReport"); return true; // qDebug() << "Done; " << Speed_max << "/" << Speed_avg << "; " << graphPoints.count() << "points"; }
void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event)) { wxTextCtrl& textCtrl = * GetTextCtrl(); textCtrl.Clear(); textCtrl << _T("\nTest fstream vs. wxFileStream:\n\n"); textCtrl.WriteText( _T("Writing to ofstream and wxFileOutputStream:\n") ); wxSTD ofstream std_file_output( "test_std.dat" ); wxFileOutputStream file_output( file_name ); wxBufferedOutputStream buf_output( file_output ); wxTextOutputStream text_output( buf_output ); wxString tmp; signed int si = 0xFFFFFFFF; tmp.Printf( _T("Signed int: %d\n"), si ); textCtrl.WriteText( tmp ); text_output << si << _T("\n"); std_file_output << si << "\n"; unsigned int ui = 0xFFFFFFFF; tmp.Printf( _T("Unsigned int: %u\n"), ui ); textCtrl.WriteText( tmp ); text_output << ui << _T("\n"); std_file_output << ui << "\n"; double d = 2.01234567890123456789; tmp.Printf( _T("Double: %f\n"), d ); textCtrl.WriteText( tmp ); text_output << d << _T("\n"); std_file_output << d << "\n"; float f = (float)0.00001; tmp.Printf( _T("Float: %f\n"), f ); textCtrl.WriteText( tmp ); text_output << f << _T("\n"); std_file_output << f << "\n"; wxString str( _T("Hello!") ); tmp.Printf( _T("String: %s\n"), str.c_str() ); textCtrl.WriteText( tmp ); text_output << str << _T("\n"); std_file_output << str.ToAscii() << "\n"; textCtrl.WriteText( _T("\nReading from ifstream:\n") ); wxSTD ifstream std_file_input( "test_std.dat" ); std_file_input >> si; tmp.Printf( _T("Signed int: %d\n"), si ); textCtrl.WriteText( tmp ); std_file_input >> ui; tmp.Printf( _T("Unsigned int: %u\n"), ui ); textCtrl.WriteText( tmp ); std_file_input >> d; tmp.Printf( _T("Double: %f\n"), d ); textCtrl.WriteText( tmp ); std_file_input >> f; tmp.Printf( _T("Float: %f\n"), f ); textCtrl.WriteText( tmp ); char std_buf[200]; std_file_input >> std_buf; str = wxString::FromAscii(std_buf); tmp.Printf( _T("String: %s\n"), str.c_str() ); textCtrl.WriteText( tmp ); textCtrl.WriteText( _T("\nReading from wxFileInputStream:\n") ); buf_output.Sync(); wxFileInputStream file_input( file_name ); wxBufferedInputStream buf_input( file_input ); wxTextInputStream text_input( file_input ); text_input >> si; tmp.Printf( _T("Signed int: %d\n"), si ); textCtrl.WriteText( tmp ); text_input >> ui; tmp.Printf( _T("Unsigned int: %u\n"), ui ); textCtrl.WriteText( tmp ); text_input >> d; tmp.Printf( _T("Double: %f\n"), d ); textCtrl.WriteText( tmp ); text_input >> f; tmp.Printf( _T("Float: %f\n"), f ); textCtrl.WriteText( tmp ); text_input >> str; tmp.Printf( _T("String: %s\n"), str.c_str() ); textCtrl.WriteText( tmp ); textCtrl << _T("\nTest for wxDataStream:\n\n"); textCtrl.WriteText( _T("Writing to wxDataOutputStream:\n") ); file_output.SeekO( 0 ); wxDataOutputStream data_output( buf_output ); wxInt16 i16 = (unsigned short)0xFFFF; tmp.Printf( _T("Signed int16: %d\n"), (int)i16 ); textCtrl.WriteText( tmp ); data_output.Write16( i16 ); wxUint16 ui16 = 0xFFFF; tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 ); textCtrl.WriteText( tmp ); data_output.Write16( ui16 ); d = 2.01234567890123456789; tmp.Printf( _T("Double: %f\n"), d ); textCtrl.WriteText( tmp ); data_output.WriteDouble( d ); str = _T("Hello!"); tmp.Printf( _T("String: %s\n"), str.c_str() ); textCtrl.WriteText( tmp ); data_output.WriteString( str ); buf_output.Sync(); textCtrl.WriteText( _T("\nReading from wxDataInputStream:\n") ); file_input.SeekI( 0 ); wxDataInputStream data_input( buf_input ); i16 = data_input.Read16(); tmp.Printf( _T("Signed int16: %d\n"), (int)i16 ); textCtrl.WriteText( tmp ); ui16 = data_input.Read16(); tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 ); textCtrl.WriteText( tmp ); d = data_input.ReadDouble(); tmp.Printf( _T("Double: %f\n"), d ); textCtrl.WriteText( tmp ); str = data_input.ReadString(); tmp.Printf( _T("String: %s\n"), str.c_str() ); textCtrl.WriteText( tmp ); }
int main(void) { /* USER CODE BEGIN 1 */ my_usb_init(); /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_TIM1_Init(); MX_USB_DEVICE_Init(); MX_USART3_UART_Init(); MX_TIM2_Init(); /* USER CODE BEGIN 2 */ HAL_TIM_Base_Start(&htim2); delay_us_init(&htim2); softserial_init(SOFTSERIAL_TX_GPIO_Port, SOFTSERIAL_TX_Pin); hmi_lcd_init(&huart3); cpu_ctrl_init(&htim1); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ HAL_Delay(100); hsc_stop(); cpu_reset(); lcd_clear(); addr_input(); data_input(); build_ui(); HAL_Delay(100); while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ if(is_running == 0) addr_data_display_update(); // z80 reset button if(is_button_1_pressed) { hsc_stop(); cpu_reset(); lcd_print_width(130, 110, 180, 45, "CYAN", "RESET"); is_button_1_pressed = 0; HAL_Delay(500); build_ui(); } // clk step button if(is_button_3_pressed) { hsc_stop(); cycle_clock(1); lcd_print_width(130, 110, 180, 45, "RED", "CLK STEP"); is_button_3_pressed = 0; HAL_Delay(100); build_ui(); } // ins step button if(is_button_4_pressed) { hsc_stop(); lcd_print_width(130, 110, 180, 45, "GREEN", "INS STEP"); // cycle clock until we're at next M1 cycle while(HAL_GPIO_ReadPin(CPU_CTRL_PORT, M1_Pin) == LOW) cycle_clock(1); while(HAL_GPIO_ReadPin(CPU_CTRL_PORT, M1_Pin) == HIGH) cycle_clock(1); is_button_4_pressed = 0; HAL_Delay(100); build_ui(); } // run/stop button if(is_button_5_pressed) { is_running = (is_running + 1) % 2; if(is_running) { lcd_print_width(130, 110, 180, 45, "GREEN", "RUNNING"); hsc_start(); } else { hsc_stop(); build_ui(); } is_button_5_pressed = 0; } usb_data = my_usb_readline(); if(usb_data != NULL && strstr(usb_data, "epm") != NULL) { hsc_stop(); program_mode(); build_ui(); } } /* USER CODE END 3 */ }
void palm_installer::load_user_data() { wxUint32 string_length; wxUint8 count; bool found_user; wxUint8 empty_spaces; wxUint8 unused; wxUint8 single_character; wxString name_with_colons_replaced; wxLogDebug( "Attempting to load filestream" ); wxString dat_fullname = get_palm_desktop_path() + "/Palm Users"; wxLogDebug( "Looking for Palm Users dat file=" + dat_fullname ); // Make sure the file exists if ( ! wxFileExists( dat_fullname ) ) { // Note: a checkbox message dialog, casuses a crash when opening config dialog // if it was active. Therefore, no checkbox message dialog // Abort now. Can't read configuration from Registry. return; } // Create the object wxFile dat_file( dat_fullname ); // Make sure that file was opened properly. I am not going to make a checkbox removable // dialog since there is almost zero chance that it won't open. if ( ! dat_file.IsOpened() ) { wxLogError( "Error: unable to load file named " + dat_fullname ); // Need to return here or else will get in trouble later. return; } // Build an input stream from the file. Note we could have skipped right to // this function with the wxFileInputStream( wxString filename ) function, but // then it is harder to see what went wrong. wxFileInputStream userData( dat_file ); wxLogDebug( "Loaded filestream" ); // Seek to 7, which will be number of users. //! \todo Should this be reading 4,5,6,7 instead? if more than 128 users? userData.SeekI( 7 ); wxLogDebug( "SeekI to offset of 7" ); // Make a buffered input stream from file stream wxBufferedInputStream buf_input( userData ); wxLogDebug( "Loaded Bufferedinput stream from filestream" ); // Make a data input stream from the buffered input stream wxDataInputStream data_input( buf_input ); wxLogDebug( "Loaded DataInputStream from buffered filestream" ); // Set the Endian Order of the data stream. We want to read "0x00 0x00 0x00 0E" as // 14, not 234881024. data_input.BigEndianOrdered( TRUE ); wxLogDebug( "NOTE! Setting to Big Endian ordered data file for Palm Users file." ); // //! \todo See the 4,5,6,7 note above. // Read the number of users from the dat file. m_number_of_users = data_input.Read8(); wxLogDebug( wxT("Read m_number_of_users=%d"), (int)m_number_of_users ); if ( 0 < m_number_of_users ) { // Fast forward through 4 unneeded bytes by reading a UInt32 // This is since I don't care if NUser (user) or a CUser (profile). unused = data_input.Read32(); // Execute a loop enough times to query information about each user. for ( count = 0; count < m_number_of_users; count++ ) { // Add a new member to our array of users. // The "new" we create here, gets "delete"ed in the base class's destructor // as part of the WX_CLEAR_ARRAY macro palm_user_type* palm_user = new palm_user_type(); m_users_array.Add( palm_user ); wxLogDebug( "Added a new array element" ); // Reset value of string_length to 0, from last iteration of loop, as // a precaution. string_length = 0; // Read the user's Name // ReadString() might work because we have the correct Uint32 to tell how // long the string is. So could instead just do // m_users_array[ count ]->name = data_input.ReadString(); // However, I don't know how well it behaves with unicode. string_length = data_input.Read32(); wxLogDebug( "Read string_length=%u", string_length ); for ( int j = 0; j < string_length; j++ ) { single_character = data_input.Read8(); m_users_array[ count ]->name += (wxChar)single_character; } wxLogDebug( wxT( "Read user_name=%s" ), m_users_array[ count ]->name.c_str() ); // Make a dummy magic number of 0 m_users_array[ count ]->magic = 0; wxLogDebug( wxT("On OSX, just using a dummy magic number of %lu"), m_users_array[ count ]->magic ); // Read the user's subdirectory (I am assuming that all 4 bytes are for the // string length) name_with_colons_replaced = m_users_array[ count ]->name; name_with_colons_replaced.Replace( ":", "-" ); m_users_array[ count ]->subdirectory = name_with_colons_replaced; wxLogDebug( wxT( "user subdirectory calculated from username as=%s" ), m_users_array[ count ]->subdirectory.c_str() ); // Zip through rest of crap until find the next user entry if ( count < m_number_of_users - 1 ) { wxLogDebug( "Entering search for next user..." ); found_user = FALSE; // A signal for the next user/profile entry is either the sequence: // 0x4E 0x55 0x73 0x72 (78 85 115 114 which spells NUsr), or // 0x43 0x55 0x73 0x72 (67 85 115 114 which spells CUsr) while ( ! found_user ) { // Read the next character single_character = data_input.Read8(); // If the single character is 78 or 67.... if ( ( single_character == 78 ) || ( single_character == 67 ) ) { // Read the next character single_character = data_input.Read8(); // ...and it is followed by a 85... if ( single_character == 85 ) { // Read the next character single_character = data_input.Read8(); // ...and it is followed by a 85... if ( single_character == 115 ) { // Read the next character single_character = data_input.Read8(); // ...and it is followed by a 85... if ( single_character == 114 ) { wxLogDebug( "Found next user. Restarting loop to query info" ); // ...Got a user. break. found_user = TRUE; } } } } } } } } }
void FuzzyDetector::LoadFromXml(QString settingsFileName) { QFile data_input(settingsFileName); if(! data_input.open(QFile::ReadOnly | QFile::Text)) { qDebug() << "Could not load settings, creating new one!"; SaveToXml(settingsFileName); return; } QXmlStreamReader xml; xml.setDevice(&data_input); fp_onAir.clear(); fp_onGrnd.clear(); pa_onAir.clear(); pa_onGrnd.clear(); ia_onAir.clear(); ia_onGrnd.clear(); if(xml.readNextStartElement()) { if(xml.name() != "FuzzyDetectorSettings") { qDebug() << "not a fuzzy detector log file"; return; } } do { while( xml.readNextStartElement()) { if(xml.name() == "FP_OnAir") { do { while(xml.readNextStartElement()) { if(xml.name() == "relation") { fp_onAir.push_back(Relation( xml.attributes().value("inVal").toString().toDouble(), xml.attributes().value("outVal").toString().toDouble() )); } else { xml.skipCurrentElement(); } } } while(xml.name() != "FP_OnAir"); } else if(xml.name() == "FP_OnGrnd") { do { while(xml.readNextStartElement()) { if(xml.name() == "relation") { fp_onGrnd.push_back(Relation( xml.attributes().value("inVal").toString().toDouble(), xml.attributes().value("outVal").toString().toDouble() )); } else { xml.skipCurrentElement(); } } } while(xml.name() != "FP_OnGrnd"); } else if(xml.name() == "PA_OnAir") { do { while(xml.readNextStartElement()) { if(xml.name() == "relation") { pa_onAir.push_back(Relation( xml.attributes().value("inVal").toString().toDouble(), xml.attributes().value("outVal").toString().toDouble() )); } else { xml.skipCurrentElement(); } } } while(xml.name() != "PA_OnAir"); } else if(xml.name() == "PA_OnGrnd") { do { while(xml.readNextStartElement()) { if(xml.name() == "relation") { pa_onGrnd.push_back(Relation( xml.attributes().value("inVal").toString().toDouble(), xml.attributes().value("outVal").toString().toDouble() )); } else { xml.skipCurrentElement(); } } } while(xml.name() != "PA_OnGrnd"); } else if(xml.name() == "IA_OnAir") { do { while(xml.readNextStartElement()) { if(xml.name() == "relation") { ia_onAir.push_back(Relation( xml.attributes().value("inVal").toString().toDouble(), xml.attributes().value("outVal").toString().toDouble() )); } else { xml.skipCurrentElement(); } } } while(xml.name() != "IA_OnAir"); } else if(xml.name() == "IA_OnGrnd") { do { while(xml.readNextStartElement()) { if(xml.name() == "relation") { ia_onGrnd.push_back(Relation( xml.attributes().value("inVal").toString().toDouble(), xml.attributes().value("outVal").toString().toDouble() )); } else { xml.skipCurrentElement(); } } } while(xml.name() != "IA_OnGrnd"); } else { xml.skipCurrentElement(); } } }while(xml.name() != "FuzzyDetectorSettings"); }