c++ - Reading cstrings of different length from an input text file into a linked list -


I am currently working on an assignment which gives me an input text file name and other different data to a linked list To read in I say using seestering I have reduced all the necessary components One thing is all but one of the names has three words in the last line of the input text file to read the input text file properly to see my loop To f There are only two words in the throw. Input text file is as follows:

12345678901234567890123456789012345678901234567890

Worms Bunny Junior 1234 1001.01

Dr. Willy Coyote 2345 1002.02

Taco Promo Gonzales 3456 1003.03

Billy Goat 4567 1004.04

Porky Pig 5678 1005.05

Here is my code function To:

  zero input FN (customer type * and head) {customerType * currptr, * nnptr; Head = zero; Fin.ignore (50, '\ n'); While (feathers) {// Create the first node if the head is zero (head == faucet) {head = new customer type; Wings & gt; & Gt; Head & gt; Name [0] & gt; & Gt; Head & gt; Name [1] & gt; & Gt; Head & gt; Name [2] & gt; & Gt; Head & gt; Pin & gt; & Gt; Head & gt; Balance; Currptr = head; If (fin.peek () == '\ n') fin.ignore (); // If there is only one record, // the end of the first node nnptr = new customerType; Wings & gt; & Gt; Nnptr-> Name [0] & gt; & Gt; Nnptr-> Name [1] & gt; & Gt; Nnptr-> Name [2] & gt; & Gt; Nnptr-> Pin & gt; & Gt; Nnptr-> Balance; Currptr-> Link = nnptr; // nodes cryptor = NNPTR; // is connected to Advanced Curator if (fin.peak)) == '\ n') Finn.igner (); } // the end of creating a linked list // at the end of //} after the end of inputfn  

it is reading three names; Instead of the last name is placed as the pin. This is causing the cause of my output to look like this:

Insect-borne junior 1234 1001.01

Dr. Wiley Coyote 2345 1002.02

Taco Promo Gonzales 3456 1003.03

Billy Goat 4567 1004.04

Porky Pig 5678 1005 05

I know there There should be an easy fix for this problem, but since I have to use a loop to read the data, I am having trouble finding the answers. Any help would be appreciated.

I do not believe there is a "easy fix" but general, "I have a text The row in which contains a variable number of elements of a particular divisor, for "the theory is to read it in a string, and then to check that the input has 1, 2 or 3 elements (think Superman 9876 4123.09 as input also)

An approach, to calculate the number of separators will be (Spaces in this case):

  std: string line; Gateline (feather, line); Of vector & lt; Int & gt; Space_loc; (Int i = 0; i & lt; line.size (); i ++) {// Do we have a location? If (line [i] == '') {space_loc.push_back (i); // Skip Multiple Spaces (i & lt; line.size () & amp; amp; Line [i] == '') {}}} If (space_loc.size () == 4) {... / * We have three names * /} Else if (space_loc () == 3) {... / * We have only two names ... ... more stuff here - controlling the error when data is incomplete Remember for  

I also need to make sure that the code only makes one read-statement, instead of two, you might do this:

  Nnptr = Type new customer; ... Read in NNPTR ... if (head == NULL) currptr = head = nnptr; Other currptr-> gt; Next = nnptr;  

(This avoids a problem in your code when there is only one record in the input file)


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -