Thread: From it string to vector of strings.

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    44

    Question From it string to vector of strings.

    From it string to vector of strings.



    EXAMPLE I HAVE ONE I string "HELLO KRAKZ GOOD Day" I I WANT TO REALIZE a stringes vector "hello" "krakz" "good" day " knowledge as I can make?




    string = "CIAO MAMMA COME VA"

    strivect[0]= "CIAO"
    strivect[1]= "MAMMA"
    strivect[2]= "COME"
    strivect[3]= "VA"

    ????
    http://linuxdesktop.it

  2. #2
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807

    hmm, check the spaces...

    if it contains an space, new word.
    and like this goe's..

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    44
    Not rembember algorithm ;(
    http://linuxdesktop.it

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You can use strchr() to find one character within a char array, if that's what you want.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Dec 2002
    Posts
    44
    Code:
    /*
      Name: WINERASER ( WINERASER IS NOT ERASER )
      Author: KRAKZ 
      Date: 05/01/03 10.01
      Description: UTILITA RIMOZIONE FILE
      LICENZA : GNU|GPL
      VERSIONE : 0.0.2 ( RIESCE A LEGGERE IL FILE ERASER.TXT )
      NOTE : AL MOMENTO IL PROGRAMMA NON FUNZIONA , RIESCE A GENERARE IL FILE BATCH , E A LEGGERE 
      I RISULTATI DEL FILE BATCH*/
    
    # include <stdio.h>
    # define Max 1000000
    
    void scrivitmp();
    void leggitmp();
    void error(int error) ;
    void debug (char stamp) ;
    void batchtmp (char batch[Max]) ;
    
    main ()
    
    { scrivitmp(); 
      leggitmp();  
    }
    
    
    
    
    
    /* REALIZZO DEL FILE BATCH */
    void scrivitmp()
    {
    FILE *cfPtr ;
    
    
    if (( cfPtr = fopen ("eraser.bat" , "w" )) == NULL ) 
        printf ("FILE GIA APERTO\n") ;
    else { fprintf ( cfPtr , "dir *.tmp /s /a  >ERASER.txt\n");}
    } 
    
    /* LEGGE IL FILE ERASER.TXT */
    void leggitmp()
    {
    char leggitmp[Max];
    FILE *cfPtr ;
    FILE *tmp ;
    if (( cfPtr = fopen ("ERASER.txt" , "r" )) == NULL ) 
    error(1) ;
    else 
    { 
    printf ("wait\n") ;
    while (!feof(cfPtr)) 
    {
    printf (".") ;
    fread ( &leggitmp , sizeof (leggitmp) , 1, cfPtr) ;
    } 
    if (( tmp = fopen ("tmp.log" , "w" )) == NULL ) 
                       printf ("FILE GIA APERTO\n") ;
    else {fprintf ( tmp , "%s", &leggitmp[1]);      /* SICURAMENTE SBAGLIATO*/
    }
    }
    batchtmp (leggitmp) ;
    }
    
    
    
    
    
    /* LETTURA ERRORI */
    void error(int error)
    
    {
    FILE *cfPtr ;
    if (( cfPtr = fopen ("errore.txt" , "w" )) == NULL )
    printf ("ERRORE\n ")  ;
    else 
    { 
    printf ("IN CASO ERRORE ,INVIARE IL FILE TXT DELL ERRORE A [email protected]");
    fprintf ( cfPtr , "ERRORE IN %d" , error );
    }
    }
    
    /* INTERPETRA IL FILE ERASER.TXT E REALIZZA UN FILE BATCH */
    
    void batchtmp  (char batchtmp[Max])
    {
    printf ("%s" , &batchtmp[1]) ;
    }
    my problem is
    open file bat whit my porgramm
    read file of file bat
    Code:
    /* LEGGE IL FILE ERASER.TXT */
    void leggitmp()
    {
    char leggitmp[Max];
    FILE *cfPtr ;
    FILE *tmp ;
    if (( cfPtr = fopen ("ERASER.txt" , "r" )) == NULL ) 
    error(1) ;
    else 
    { 
    printf ("wait\n") ;
    while (!feof(cfPtr)) 
    {
    printf (".") ;
    fread ( &leggitmp , sizeof (leggitmp) , 1, cfPtr) ;
    } 
    if (( tmp = fopen ("tmp.log" , "w" )) == NULL ) 
                       printf ("FILE GIA APERTO\n") ;
    else {fprintf ( tmp , "%s", &leggitmp[1]);      /* SICURAMENTE SBAGLIATO*/
    }
    }
    batchtmp (leggitmp) ;
    }
    and write new file batch for delete file
    http://linuxdesktop.it

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >EXAMPLE I HAVE ONE I string "HELLO KRAKZ GOOD Day" I I WANT TO REALIZE a stringes vector "hello" "krakz" "good" day "
    Code:
    #include <stdio.h>
    #include <ctype.h>
    
    static int make_argv ( char *s, char *argv[], int argvsize )
    {
      int i, argc = 0;
      char *p = s;
      
      for ( i = 0; i < argvsize; i++ ) {
        while ( isspace ( *p ) )
          p++;
        
        if ( *p != '\0' )
          argv[argc++] = p;
        else {
          argv[argc] = NULL;
          break;
        }
        
        while ( *p != '\0' && !isspace ( *p ) )
          p++;
        
        if ( *p != '\0' && i < argvsize - 1 )
          *p++ = '\0';
      }
      
      return argc;
    }
    
    int main ( void )
    {
      int i, argc;
      char *argv[10];
      char a[] = "This is a test";
      
      argc = make_argv ( a, argv, 10 );
      
      for ( i = 0; i < argc; i++ )
        printf ( "%s\n", argv[i] );
    
      return 0;
    }
    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. Help! Homework using Strings
    By wco5002 in forum C++ Programming
    Replies: 16
    Last Post: 09-27-2007, 03:53 AM
  3. Strings - char mystring[n] vs. string mystring
    By Diablo84 in forum C++ Programming
    Replies: 12
    Last Post: 04-06-2005, 05:54 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Again Character Count, Word Count and String Search
    By client in forum C Programming
    Replies: 2
    Last Post: 05-09-2002, 11:40 AM