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. To read a complete string

To read a complete string

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
17 Posts 5 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.
  • P Pankaj D Dubey

    Hi All, i want to write a code to read a complete string. The code i have written reads the first word of every string. What all modification is it required to do the same? I am ucing MFC for the same. Thank u all

    French is the language of love, for everything else there is c++ ...(anonymous)

    C Offline
    C Offline
    Chandrasekharan P
    wrote on last edited by
    #2

    You can use CStdioFile::ReadString http://msdn.microsoft.com/en-us/library/x5t0zfyf(VS.80).aspx[^]

    1 Reply Last reply
    0
    • P Pankaj D Dubey

      Hi All, i want to write a code to read a complete string. The code i have written reads the first word of every string. What all modification is it required to do the same? I am ucing MFC for the same. Thank u all

      French is the language of love, for everything else there is c++ ...(anonymous)

      M Offline
      M Offline
      Madhu Nair 0
      wrote on last edited by
      #3

      dubeypankaj wrote:

      The code i have written reads the first word of every string.

      Your code to read string may have a bug! That may be stop reading on each SPACE character. You can use strlen to find the length of the complete string.

      dubeypankaj wrote:

      I am ucing MFC for the same.

      In MFC the string manipulations are done with CString class.

      1 Reply Last reply
      0
      • P Pankaj D Dubey

        Hi All, i want to write a code to read a complete string. The code i have written reads the first word of every string. What all modification is it required to do the same? I am ucing MFC for the same. Thank u all

        French is the language of love, for everything else there is c++ ...(anonymous)

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #4

        Your question is not clear. Where are you reading from? File? Standard input? How are you reading it? scanf? cin? I'm assuming that you are reading from standard input, ie, user input. If you are using scanf, you can do this -

        char sz[1024];
        scanf("%[^\n]", sz);

        If you are using cin, you can do this -

        string s;
        getline(cin,s);

        «_Superman_» I love work. It gives me something to do between weekends.

        P 1 Reply Last reply
        0
        • _ _Superman_

          Your question is not clear. Where are you reading from? File? Standard input? How are you reading it? scanf? cin? I'm assuming that you are reading from standard input, ie, user input. If you are using scanf, you can do this -

          char sz[1024];
          scanf("%[^\n]", sz);

          If you are using cin, you can do this -

          string s;
          getline(cin,s);

          «_Superman_» I love work. It gives me something to do between weekends.

          P Offline
          P Offline
          Pankaj D Dubey
          wrote on last edited by
          #5

          No, I m not using cin or scanf, i am reading data from a text file, and storing the outputs in arrays and again giving these array values as input to the textboxes so as to get an onscreen display of tht perticular text box.

          French is the language of love, for everything else there is c++ ...(anonymous)

          _ 1 Reply Last reply
          0
          • P Pankaj D Dubey

            No, I m not using cin or scanf, i am reading data from a text file, and storing the outputs in arrays and again giving these array values as input to the textboxes so as to get an onscreen display of tht perticular text box.

            French is the language of love, for everything else there is c++ ...(anonymous)

            _ Offline
            _ Offline
            _Superman_
            wrote on last edited by
            #6

            You can getline on the file stream to read one line at a time.

            «_Superman_» I love work. It gives me something to do between weekends.

            P 1 Reply Last reply
            0
            • _ _Superman_

              You can getline on the file stream to read one line at a time.

              «_Superman_» I love work. It gives me something to do between weekends.

              P Offline
              P Offline
              Pankaj D Dubey
              wrote on last edited by
              #7

              fopen("some_file.txt","r"); Search(fp_mt2, "Text: 2", "xyz"); for(i = 0; i < 10; i++) { fgets(line_buffer, 200, fp_mt2); j=0; while(line_buffer[j]!='(') { j++; } j = j + 2; mt2[i] = line_buffer[j]; } m_txt = mt2[0]; " " " " " "........ some 10 times w.r.t every value of mt2[j] m-txt is the textbox. But i am getting only first character of every string of every line. The string carry 2 or 3 characters. j = to reach the perticular line. would u please help me further.

              French is the language of love, for everything else there is c++ ...(anonymous)

              _ 1 Reply Last reply
              0
              • P Pankaj D Dubey

                fopen("some_file.txt","r"); Search(fp_mt2, "Text: 2", "xyz"); for(i = 0; i < 10; i++) { fgets(line_buffer, 200, fp_mt2); j=0; while(line_buffer[j]!='(') { j++; } j = j + 2; mt2[i] = line_buffer[j]; } m_txt = mt2[0]; " " " " " "........ some 10 times w.r.t every value of mt2[j] m-txt is the textbox. But i am getting only first character of every string of every line. The string carry 2 or 3 characters. j = to reach the perticular line. would u please help me further.

                French is the language of love, for everything else there is c++ ...(anonymous)

                _ Offline
                _ Offline
                _Superman_
                wrote on last edited by
                #8

                Your last post was very confusing. I didn't quite understand.

                «_Superman_» I love work. It gives me something to do between weekends.

                M P 2 Replies Last reply
                0
                • _ _Superman_

                  Your last post was very confusing. I didn't quite understand.

                  «_Superman_» I love work. It gives me something to do between weekends.

                  M Offline
                  M Offline
                  Madhu Nair 0
                  wrote on last edited by
                  #9

                  :-D Yes it is! :sigh:

                  1 Reply Last reply
                  0
                  • _ _Superman_

                    Your last post was very confusing. I didn't quite understand.

                    «_Superman_» I love work. It gives me something to do between weekends.

                    P Offline
                    P Offline
                    Pankaj D Dubey
                    wrote on last edited by
                    #10

                    sorry for the same... fopen("some_file.txt","r"); // opening the text file to read Search(fp_mt2, "Text: 2", "xyz"); // search string xyz after string Text for(i = 0; i < 10; i++) // reading 10 strings from 10 lines { // (starting string from each line) fgets(line_buffer, 200, fp_mt2); // reading a line here j=0; while(line_buffer[j]!=':') // starts reading after ':' { j++; } j = j + 2; mt2[i] = line_buffer[j]; // storing the string in an array } m_txt1 = mt2[0]; // output: displaying first string m_txt2 = mt2[1]; // output: displaying second string .............. .............. m_txt10 = mt2[9]; m_txt is the textbox. now, i want to read a complete string but i am getting only first character of every string of every line. where each string carry 2 or 3 characters. would u please help me further, now ?

                    French is the language of love, for everything else there is c++ ...(anonymous)

                    C _ 2 Replies Last reply
                    0
                    • P Pankaj D Dubey

                      sorry for the same... fopen("some_file.txt","r"); // opening the text file to read Search(fp_mt2, "Text: 2", "xyz"); // search string xyz after string Text for(i = 0; i < 10; i++) // reading 10 strings from 10 lines { // (starting string from each line) fgets(line_buffer, 200, fp_mt2); // reading a line here j=0; while(line_buffer[j]!=':') // starts reading after ':' { j++; } j = j + 2; mt2[i] = line_buffer[j]; // storing the string in an array } m_txt1 = mt2[0]; // output: displaying first string m_txt2 = mt2[1]; // output: displaying second string .............. .............. m_txt10 = mt2[9]; m_txt is the textbox. now, i want to read a complete string but i am getting only first character of every string of every line. where each string carry 2 or 3 characters. would u please help me further, now ?

                      French is the language of love, for everything else there is c++ ...(anonymous)

                      C Offline
                      C Offline
                      Chandrasekharan P
                      wrote on last edited by
                      #11

                      Send an example of your text file. I don't think people here has understood your file format.

                      1 Reply Last reply
                      0
                      • P Pankaj D Dubey

                        sorry for the same... fopen("some_file.txt","r"); // opening the text file to read Search(fp_mt2, "Text: 2", "xyz"); // search string xyz after string Text for(i = 0; i < 10; i++) // reading 10 strings from 10 lines { // (starting string from each line) fgets(line_buffer, 200, fp_mt2); // reading a line here j=0; while(line_buffer[j]!=':') // starts reading after ':' { j++; } j = j + 2; mt2[i] = line_buffer[j]; // storing the string in an array } m_txt1 = mt2[0]; // output: displaying first string m_txt2 = mt2[1]; // output: displaying second string .............. .............. m_txt10 = mt2[9]; m_txt is the textbox. now, i want to read a complete string but i am getting only first character of every string of every line. where each string carry 2 or 3 characters. would u please help me further, now ?

                        French is the language of love, for everything else there is c++ ...(anonymous)

                        _ Offline
                        _ Offline
                        _Superman_
                        wrote on last edited by
                        #12

                        And how is mt2 declared? Also how are m_txt1, m_txt2 etc. declared?

                        «_Superman_» I love work. It gives me something to do between weekends.

                        R P 2 Replies Last reply
                        0
                        • _ _Superman_

                          And how is mt2 declared? Also how are m_txt1, m_txt2 etc. declared?

                          «_Superman_» I love work. It gives me something to do between weekends.

                          R Offline
                          R Offline
                          Rajesh R Subramanian
                          wrote on last edited by
                          #13

                          I'm giving you a 5 for your tolerance. :)

                          It is a crappy thing, but it's life -^ Carlo Pallini

                          _ 1 Reply Last reply
                          0
                          • _ _Superman_

                            And how is mt2 declared? Also how are m_txt1, m_txt2 etc. declared?

                            «_Superman_» I love work. It gives me something to do between weekends.

                            P Offline
                            P Offline
                            Pankaj D Dubey
                            wrote on last edited by
                            #14

                            Send an example of your text file. I don't think people here has understood your file format.... (from ur previous post) #Its a text file(notepad.txt) Text: 2 Parity: fad90 xyz: 01110000 00000000 00000100 10110000 00000010 00000000 00000000 00000000 00001001 01100000 01000101 00000000 00000000 00000000 11011001 00010000 00000000 00000000 00001111 01111100 11101100 01001110 11101101 11011110 11101101 11101110 1101 ABCD: 1 EFGH: 3 Correction[ 1 ]: 0 (0, 0m) Correction[ 2 ]: 4b (75, 9.375m) Correction[ 3 ]: 2 (2, 0.25m) Correction[ 4 ]: 0 (0, 0m) Correction[ 5 ]: 0 (0, 0m) Correction[ 6 ]: 96 (150, 18.75m) Correction[ 7 ]: 45 (69, 8.625m) Correction[ 8 ]: 0 (0, 0m) Correction[ 9 ]: 0 (0, 0m) Correction[ 10 ]: d91 (3473, -77.875m) Correction[ 11 ]: 0 (0, 0m) Correction[ 12 ]: 0 (0, 0m) Correction[ 13 ]: f7c (3964, -16.5m) I am only getting first character after ':'(not reading newline character) every time but getting, for ex: 4(instead of 4b), d(instead of d91) & so on. mt2 is declared as: char mt2[15]; m_txt1, m_txt2 are the textboxes takes Value(not control) and declared as type CString. Hope this much info. will be sufficient for you people. Even i am trying for the same and hope to get it right soon. Thank you all once again for showing interest in my problem. (Plz follow the previous link to check the code)

                            French is the language of love, for everything else there is c++ ...(anonymous)

                            _ 1 Reply Last reply
                            0
                            • R Rajesh R Subramanian

                              I'm giving you a 5 for your tolerance. :)

                              It is a crappy thing, but it's life -^ Carlo Pallini

                              _ Offline
                              _ Offline
                              _Superman_
                              wrote on last edited by
                              #15

                              Thank you... Thank you... Thank you... Thank you... Thank you...

                              «_Superman_» I love work. It gives me something to do between weekends.

                              1 Reply Last reply
                              0
                              • P Pankaj D Dubey

                                Send an example of your text file. I don't think people here has understood your file format.... (from ur previous post) #Its a text file(notepad.txt) Text: 2 Parity: fad90 xyz: 01110000 00000000 00000100 10110000 00000010 00000000 00000000 00000000 00001001 01100000 01000101 00000000 00000000 00000000 11011001 00010000 00000000 00000000 00001111 01111100 11101100 01001110 11101101 11011110 11101101 11101110 1101 ABCD: 1 EFGH: 3 Correction[ 1 ]: 0 (0, 0m) Correction[ 2 ]: 4b (75, 9.375m) Correction[ 3 ]: 2 (2, 0.25m) Correction[ 4 ]: 0 (0, 0m) Correction[ 5 ]: 0 (0, 0m) Correction[ 6 ]: 96 (150, 18.75m) Correction[ 7 ]: 45 (69, 8.625m) Correction[ 8 ]: 0 (0, 0m) Correction[ 9 ]: 0 (0, 0m) Correction[ 10 ]: d91 (3473, -77.875m) Correction[ 11 ]: 0 (0, 0m) Correction[ 12 ]: 0 (0, 0m) Correction[ 13 ]: f7c (3964, -16.5m) I am only getting first character after ':'(not reading newline character) every time but getting, for ex: 4(instead of 4b), d(instead of d91) & so on. mt2 is declared as: char mt2[15]; m_txt1, m_txt2 are the textboxes takes Value(not control) and declared as type CString. Hope this much info. will be sufficient for you people. Even i am trying for the same and hope to get it right soon. Thank you all once again for showing interest in my problem. (Plz follow the previous link to check the code)

                                French is the language of love, for everything else there is c++ ...(anonymous)

                                _ Offline
                                _ Offline
                                _Superman_
                                wrote on last edited by
                                #16

                                dubeypankaj wrote:

                                mt2 is declared as: char mt2[15];

                                This can store only 1 string. This needs to become char mt2[15][1024]; In fact I recommend CStringArray.

                                dubeypankaj wrote:

                                mt2[i] = line_buffer[j]; // storing the string in an array

                                You cannot assign a string like this for a character array. Use strcpy_s. You can use = if you are using CString[] or CStringArray.

                                «_Superman_» I love work. It gives me something to do between weekends.

                                P 1 Reply Last reply
                                0
                                • _ _Superman_

                                  dubeypankaj wrote:

                                  mt2 is declared as: char mt2[15];

                                  This can store only 1 string. This needs to become char mt2[15][1024]; In fact I recommend CStringArray.

                                  dubeypankaj wrote:

                                  mt2[i] = line_buffer[j]; // storing the string in an array

                                  You cannot assign a string like this for a character array. Use strcpy_s. You can use = if you are using CString[] or CStringArray.

                                  «_Superman_» I love work. It gives me something to do between weekends.

                                  P Offline
                                  P Offline
                                  Pankaj D Dubey
                                  wrote on last edited by
                                  #17

                                  Thank you. Thank you very much for ur support. And ofcourse thank you for tolerating me as well..(as commented by Rajesh)

                                  French is the language of love, for everything else there is c++ ...(anonymous)

                                  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