Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Wert suchen ausgeben

Empfohlene Antworten

Veröffentlicht

es ist nur kleines Programm in C++. Es geht soweit, weiss jemand per Zufall wie ich das dritte Wort des C-Strings ausgeben kann? Die Ziffernfolge 0039049 wäre eigentlich nicht bekannt und das Programm muss solange suchen, bis es merkt das ein anderer Wert kommt als 20 (Leerzeichen), dass eine Ziffer kommt und dort muss es das dritte Wort (fett markiert) nehmen und ausgeben.

Dev C++

#include <cstdlib> 

#include <iostream> 


using namespace std; 


int main(int argc, char *argv[]) 

{ 

  char str[] = " 0    AZ     0039049 001522300x"; 

  char * pch; 

  pch=strchr(str,' ');// NULL an letzter Stelle 

  printf("Die Ziffernfolge 00122300 kommt an Stelle %d vor\n",pch-str+1); 


    system("PAUSE"); 

    return 0; 

}

Wenn es C++ sein soll, sollte man auch die Möglichkeiten von C++ nutzen: ;)

#include <sstream> 
#include <string>
#include <iostream>

using namespace std;

int main()
{
string str = " 0 AZ 0039049 001522300x";
string s;
istringstream stream( str );
stream >> s >> s >> s;

string::size_type pos = str.find( s );

cout << "Die Ziffernfolge " << s << " kommt an Stelle " << pos << " vor\n";
}[/code]

Hej Klotzkopp, danke dir!

hab noch diese Lösung erarbeitet.

#include <vector> 

#include <string> 

#include <iostream> 


using namespace std; 


int main( ) 

{ 

    const char str[ ] = " 0 AZ 00-9049 001522300x"; 


    std::string temp( str ); 


    //std::string::size_type pos        = temp.find( ' ', 0 ); 

    //std::string::size_type old_pos    = 0; 


    std::vector< std::string > substrings; 

    int pos = 0;

    int start_pos = 0;

    int end_pos = 0;

    bool found = false;

    while(str[pos] != 0) { 

        if( (str[pos] > 47 && str[pos] < 58) || (str[pos] > 64 && str[pos] < 91)){

             if(found){

                 end_pos = pos+1;

             }

             else{

                 found = true;

                 start_pos = pos;

                 end_pos = pos+1;

             }

        }

        else{

             if(found){

                 substrings.push_back(temp.substr(start_pos, end_pos - start_pos));

                 start_pos = pos;

                 end_pos = pos;

                 found = false;

             }

        }

        pos++;


        //old_pos = ++pos; 

        //pos = temp.find( ' ', pos ); 


        //substrings.push_back( temp.substr( old_pos, pos - old_pos ) ); 

    } 


    for( std::vector< std::string >::size_type i = 0, size = substrings.size( ); i < size; ++i ) { 


        std::cout << i + 1 << ": " << substrings[ i ] << std::endl; 

    } 


    system("PAUSE");

    return 0;

}

Gib mir zwar alle Werte aus aber reicht. Deine iIdee ist auch super!

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.