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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem with output [modified]

Problem with output [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++
7 Posts 4 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.
  • G Offline
    G Offline
    gregarion
    wrote on last edited by
    #1

    Hey guys, i am having problem with displaying my text. my text file is displayed in such a way and is called test.......

    Sam Worthington ... Jake SullyasZoe Saldana ... NeytiriasSigourney Weaver ... Dr. Grace AugustineasStephen Lang ... Colonel Miles QuaritchasJoel Moore ... Norm Spellman (as Joel David Moore)asGiovanni Ribisi ... Parker SelfridgeasMichelle Rodriguez ... Trudy ChaconasLaz Alonso ... Tsu'teyasWes Studi ... EytukanasCCH Pounder ... MoatasDileep Rao ... Dr. Max PatelasMatt Gerald ... Corporal Lyle WainfleetasSean Anthony Moran ... Private FikeasJason Whyte ... Cryo Vault Med TechasScott Lawrence ... Venture Star Crew Chiefmore

    What i am trying to do is for the program to read "as" and then from there start a new line... thus the expected output is...

    Sam Worthington ... Jake Sully
    Zoe Saldana ... Neytiri
    Sigourney Weaver ... Dr. Grace Augustine
    Stephen Lang ... Colonel Miles Quaritch
    Joel Moore ... Norm Spellman (as Joel David Moore)
    .........(and so on)

    This is my coding..

    string templine ;
    string line;
    ifstream myfile ("test");

    while (getline (myfile,templine) )
    line.append(templine);

    char str [] = line ;
    char delims[] = "as";
    char *result = NULL;
    result = strtok( str, delims );
    while( result != NULL ) {
    printf( result );
    result = strtok( NULL, delims );
    }

    I keep getting the error saying ...

    editmain.cpp.98:error: initializer fails to determine size of 'str'

    modified on Monday, February 8, 2010 1:41 PM

    A K 2 Replies Last reply
    0
    • G gregarion

      Hey guys, i am having problem with displaying my text. my text file is displayed in such a way and is called test.......

      Sam Worthington ... Jake SullyasZoe Saldana ... NeytiriasSigourney Weaver ... Dr. Grace AugustineasStephen Lang ... Colonel Miles QuaritchasJoel Moore ... Norm Spellman (as Joel David Moore)asGiovanni Ribisi ... Parker SelfridgeasMichelle Rodriguez ... Trudy ChaconasLaz Alonso ... Tsu'teyasWes Studi ... EytukanasCCH Pounder ... MoatasDileep Rao ... Dr. Max PatelasMatt Gerald ... Corporal Lyle WainfleetasSean Anthony Moran ... Private FikeasJason Whyte ... Cryo Vault Med TechasScott Lawrence ... Venture Star Crew Chiefmore

      What i am trying to do is for the program to read "as" and then from there start a new line... thus the expected output is...

      Sam Worthington ... Jake Sully
      Zoe Saldana ... Neytiri
      Sigourney Weaver ... Dr. Grace Augustine
      Stephen Lang ... Colonel Miles Quaritch
      Joel Moore ... Norm Spellman (as Joel David Moore)
      .........(and so on)

      This is my coding..

      string templine ;
      string line;
      ifstream myfile ("test");

      while (getline (myfile,templine) )
      line.append(templine);

      char str [] = line ;
      char delims[] = "as";
      char *result = NULL;
      result = strtok( str, delims );
      while( result != NULL ) {
      printf( result );
      result = strtok( NULL, delims );
      }

      I keep getting the error saying ...

      editmain.cpp.98:error: initializer fails to determine size of 'str'

      modified on Monday, February 8, 2010 1:41 PM

      A Offline
      A Offline
      Avi Berger
      wrote on last edited by
      #2

      This is inherently flawed. You have no way to distinguish between "as" as a delimiter and "as" as 2 characters in a name. As far as your error message, since str is an array of char, you have to specify how big it is to be. You don't. Why are you mixing std::string and char arrays? Since you are using std::string, I would suggest you use it and not char arrays at this point. After you have some things more figured out, you could learn how to use char arrays. They are more demanding to get right.

      1 Reply Last reply
      0
      • G gregarion

        Hey guys, i am having problem with displaying my text. my text file is displayed in such a way and is called test.......

        Sam Worthington ... Jake SullyasZoe Saldana ... NeytiriasSigourney Weaver ... Dr. Grace AugustineasStephen Lang ... Colonel Miles QuaritchasJoel Moore ... Norm Spellman (as Joel David Moore)asGiovanni Ribisi ... Parker SelfridgeasMichelle Rodriguez ... Trudy ChaconasLaz Alonso ... Tsu'teyasWes Studi ... EytukanasCCH Pounder ... MoatasDileep Rao ... Dr. Max PatelasMatt Gerald ... Corporal Lyle WainfleetasSean Anthony Moran ... Private FikeasJason Whyte ... Cryo Vault Med TechasScott Lawrence ... Venture Star Crew Chiefmore

        What i am trying to do is for the program to read "as" and then from there start a new line... thus the expected output is...

        Sam Worthington ... Jake Sully
        Zoe Saldana ... Neytiri
        Sigourney Weaver ... Dr. Grace Augustine
        Stephen Lang ... Colonel Miles Quaritch
        Joel Moore ... Norm Spellman (as Joel David Moore)
        .........(and so on)

        This is my coding..

        string templine ;
        string line;
        ifstream myfile ("test");

        while (getline (myfile,templine) )
        line.append(templine);

        char str [] = line ;
        char delims[] = "as";
        char *result = NULL;
        result = strtok( str, delims );
        while( result != NULL ) {
        printf( result );
        result = strtok( NULL, delims );
        }

        I keep getting the error saying ...

        editmain.cpp.98:error: initializer fails to determine size of 'str'

        modified on Monday, February 8, 2010 1:41 PM

        K Offline
        K Offline
        KingsGambit
        wrote on last edited by
        #3

        Cannot assign string object to a char array as follows: char str [] = line; May be you can do as follows to correctly use tokenizer function:

        char* str = _strdup(line.c_str);
        char delims[] = "as";
        char *result = NULL;
        result = strtok( str, delims );

        while( result != NULL )
        {
        printf( result );
        result = strtok( NULL, delims );
        }

        free(str);

        L 1 Reply Last reply
        0
        • K KingsGambit

          Cannot assign string object to a char array as follows: char str [] = line; May be you can do as follows to correctly use tokenizer function:

          char* str = _strdup(line.c_str);
          char delims[] = "as";
          char *result = NULL;
          result = strtok( str, delims );

          while( result != NULL )
          {
          printf( result );
          result = strtok( NULL, delims );
          }

          free(str);

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

          It still won't work; strtok() will break on any 'a' or 's'. He will need to use strstr(), or similar.

          MVP 2010 - are they mad?

          K 1 Reply Last reply
          0
          • L Lost User

            It still won't work; strtok() will break on any 'a' or 's'. He will need to use strstr(), or similar.

            MVP 2010 - are they mad?

            K Offline
            K Offline
            KingsGambit
            wrote on last edited by
            #5

            That is true. I thought he needs to break on any 'a' or 's' :)

            L 1 Reply Last reply
            0
            • K KingsGambit

              That is true. I thought he needs to break on any 'a' or 's' :)

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

              Goodness knows why anyone would choose alphabetics as separators; I am sure none of the strtok() samples around the net suggest it.

              MVP 2010 - are they mad?

              K 1 Reply Last reply
              0
              • L Lost User

                Goodness knows why anyone would choose alphabetics as separators; I am sure none of the strtok() samples around the net suggest it.

                MVP 2010 - are they mad?

                K Offline
                K Offline
                KingsGambit
                wrote on last edited by
                #7

                Yes you are right!!! No samples around the net suggests that.

                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