file processing(input from a file)
i have a simple text file with columns first name, last name and nickname...i was trying to get the inputs from each row in the file in a c++ program....then a problem cropped up...i had left out filling columns of a few rows....here is a sample table:
avinash kumar snu
akash aks
rohan ron
now i am inputting the columns into first, last and nick field of objects of people class using c++.... now when i input for 2nd row aks goes in the 'last' field and for 3rd row rohan goes in the 'first' field and ron goes开发者_开发技巧 in the 'last' field....so can anyone suggest a way by which i can fix this up......if it cant be fixed can i at least know how many columns have actually been input(means number of columns) ?
As Brian and Andrejs have commented, you'll have to parse the file line by line. Assuming there's always at least one name and never more than three, then you have 7 possibilites (0 where there's no name):
A B C,
A B 0, A 0 C, 0 B C,
A 0 0, 0 B 0, 0 0 C
Parse the line and save the names in a temporary variable. Also save the starting position of each name within the line. In case you get less than 3 names, you can logically determine which name(s) are missing, based on max length of a line. Hope this makes sense, it's not very elegant solution :)
精彩评论