Visualizzazione dei risultati da 1 a 6 su 6

Discussione: [c++]is numeric

  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826

    [c++]is numeric

    ciao.
    ho implementato la seguente funzione :
    chemi ritorna il primo blocco solo numerico della stringa passata.
    come blocco intendo separato da spazi all' ini zio e alla fine cosi':

    aaa aaa a 123
    ritorna 123
    12a ad 44 safd
    ritorna 44 ecc...
    1qqq a2d 2a44 15 sfd
    ritorna 15


    codice:
    CString CTypicalSectionBase::ReturnFirstNumericWholeWord(CString strName)
    {
    	bool bMatched = true;
    	CString strFirstOcc = "";
    	int pos = 0;
    	for(int i = 0;(strFirstOcc = strName.Tokenize(" ",pos)) != "";i++)
    	{	
    		bMatched = true;
    		char* buffer = strFirstOcc.GetBuffer();
    		for(int j = 0; j < sizeof(buffer);j++)
    		{	
    			char c= buffer[j];
    		
    			if(!isdigit(c) )
    			{
    				bMatched = false;
    				break; 
    			}
    			
    		}
    		if(bMatched)
    			return strFirstOcc;
    	}
    	return "";
    }
    il problema è che a questa riga:
    char c= buffer[j];
    if(!isdigit(c) )// c == 0 ma entra nell if. potrebbe essere il terminatore?
    {
    bMatched = false;
    break;
    }
    }

    c == 0 ma entra nell if. potrebbe essere il terminatore?
    come posso risolvere?
    grazie.

  2. #2
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381

    Re: [c++]is numeric

    Così però fai solo quattro iterazioni. E' voluto o è un errore?
    Originariamente inviato da giuseppe500
    codice:
    		char* buffer = strFirstOcc.GetBuffer();
    		for(int j = 0; j < sizeof(buffer);j++)
    This code and information is provided "as is" without warranty of any kind, either expressed
    or implied, including but not limited to the implied warranties of merchantability and/or
    fitness for a particular purpose.

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826
    no , è un errore , come posso conoscere il count di char in buffer?
    sizeof(buffer) suppongo sia sbagliato.
    e...
    l'ultimo 0 è un terminatore?
    come si fa a tralasciarlo in maniera "elegante"?
    grazie.

  4. #4
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,466
    Originariamente inviato da giuseppe500
    come posso conoscere il count di char in buffer?
    strlen ?
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  5. #5
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826
    grazie Oregon , e..
    Originariamente inviato da giuseppe500
    l'ultimo 0 è un terminatore?
    come si fa a tralasciarlo in maniera "elegante"?
    grazie.

  6. #6
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    Originariamente inviato da giuseppe500
    l'ultimo 0 è un terminatore?
    come si fa a tralasciarlo in maniera "elegante"?
    grazie.
    strlen(buff)-1
    This code and information is provided "as is" without warranty of any kind, either expressed
    or implied, including but not limited to the implied warranties of merchantability and/or
    fitness for a particular purpose.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.