Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. char str[] help

char str[] help

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++
7 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xivShin
    wrote on last edited by
    #1

    Hi I all a newbie here. need help with this: char *strtok( char *str1, const char *str2 ); char str[] = "now # is the time for all # good men to come to the # aid of their country"; char delims[] = "#"; char *result = NULL; result = strtok( str, delims ); while( result != NULL ) { printf( "result is \"%s\"\n", result ); result = strtok( NULL, delims ); } for char str[] , how can i assign it to a variable b? so far i get this error: readin.cpp:34: error: initializer fails to determine size of ‘str Thanks alot.

    CPalliniC R G L L 5 Replies Last reply
    0
    • X xivShin

      Hi I all a newbie here. need help with this: char *strtok( char *str1, const char *str2 ); char str[] = "now # is the time for all # good men to come to the # aid of their country"; char delims[] = "#"; char *result = NULL; result = strtok( str, delims ); while( result != NULL ) { printf( "result is \"%s\"\n", result ); result = strtok( NULL, delims ); } for char str[] , how can i assign it to a variable b? so far i get this error: readin.cpp:34: error: initializer fails to determine size of ‘str Thanks alot.

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      xivShin wrote:

      char *strtok( char *str1, const char *str2 );

      What's the purpose of the above line?

      xivShin wrote:

      char str[] = "now # is the time for all # good men to come to the # aid of their country"

      Is the compiler complaining of the above line? Strange! What compiler are you using? :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • X xivShin

        Hi I all a newbie here. need help with this: char *strtok( char *str1, const char *str2 ); char str[] = "now # is the time for all # good men to come to the # aid of their country"; char delims[] = "#"; char *result = NULL; result = strtok( str, delims ); while( result != NULL ) { printf( "result is \"%s\"\n", result ); result = strtok( NULL, delims ); } for char str[] , how can i assign it to a variable b? so far i get this error: readin.cpp:34: error: initializer fails to determine size of ‘str Thanks alot.

        R Offline
        R Offline
        Raj Indian
        wrote on last edited by
        #3

        if b is a pointer: char *b = str; or if b is an array and you need to copy the whole null terminated string to it: #define SIZE 200 // or any suitable value char b[SIZE]; strcpy( b, str ); One suggestion: please use meaningful names as variable names instead of b

        CPalliniC 1 Reply Last reply
        0
        • X xivShin

          Hi I all a newbie here. need help with this: char *strtok( char *str1, const char *str2 ); char str[] = "now # is the time for all # good men to come to the # aid of their country"; char delims[] = "#"; char *result = NULL; result = strtok( str, delims ); while( result != NULL ) { printf( "result is \"%s\"\n", result ); result = strtok( NULL, delims ); } for char str[] , how can i assign it to a variable b? so far i get this error: readin.cpp:34: error: initializer fails to determine size of ‘str Thanks alot.

          G Offline
          G Offline
          Garth J Lancaster
          wrote on last edited by
          #4

          first address the issue pointed out by the esteemed CPallini then, try either char str[74] = "now # is the time for all # good men to come to the # aid of their country"; or char * str = "now # is the time for all # good men to come to the # aid of their country";

          1 Reply Last reply
          0
          • R Raj Indian

            if b is a pointer: char *b = str; or if b is an array and you need to copy the whole null terminated string to it: #define SIZE 200 // or any suitable value char b[SIZE]; strcpy( b, str ); One suggestion: please use meaningful names as variable names instead of b

            CPalliniC Offline
            CPalliniC Offline
            CPallini
            wrote on last edited by
            #5

            Raj Indian wrote:

            One suggestion: please use meaningful names as variable names instead of b

            b is soooooooooo meaningful. :rolleyes:

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            In testa che avete, signor di Ceprano?

            1 Reply Last reply
            0
            • X xivShin

              Hi I all a newbie here. need help with this: char *strtok( char *str1, const char *str2 ); char str[] = "now # is the time for all # good men to come to the # aid of their country"; char delims[] = "#"; char *result = NULL; result = strtok( str, delims ); while( result != NULL ) { printf( "result is \"%s\"\n", result ); result = strtok( NULL, delims ); } for char str[] , how can i assign it to a variable b? so far i get this error: readin.cpp:34: error: initializer fails to determine size of ‘str Thanks alot.

              L Offline
              L Offline
              loyal ginger
              wrote on last edited by
              #6

              You don't have a variable b in your program. Therefore it's hard to determine what the message means -- we don't know the type of b. So you need to offer more details.

              1 Reply Last reply
              0
              • X xivShin

                Hi I all a newbie here. need help with this: char *strtok( char *str1, const char *str2 ); char str[] = "now # is the time for all # good men to come to the # aid of their country"; char delims[] = "#"; char *result = NULL; result = strtok( str, delims ); while( result != NULL ) { printf( "result is \"%s\"\n", result ); result = strtok( NULL, delims ); } for char str[] , how can i assign it to a variable b? so far i get this error: readin.cpp:34: error: initializer fails to determine size of ‘str Thanks alot.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                xivShin wrote:

                for char str[] , how can i assign it to a variable b?

                char\* b = str;
                

                But remember that b is merely a pointer to the same string. If you want a copy then you need to use strcpy() or some derivative.

                MVP 2010 - are they mad?

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups