469,898 Members | 2,033 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Skip first 9 lines of file.

I appriate your work but...
guys i have another problm.....i wana skip first 9 lines from my data file and after skipping i wana read x,y,z at the end of file. i did but after while loop is end it again skip these 9 lines. how to solve this.

and also i wana distinguish these float data and unsigned data, as you can see in data file. after 9 lines, 6 lines are the float data, after this 6 lines are unsigned int.

actually this file has a point data information. float information are the vertices and int. infromation are the faces information.
this is the data...
#Version 1.0
Shell type : GENERIC
Projection Matrix
1.0000000000 0.0000000000 0.0000000000 0.0000000000
0.0000000000 1.0000000000 0.0000000000 0.0000000000
0.0000000000 0.0000000000 1.0000000000 0.0000000000
0.0000000000 0.0000000000 0.0000000000 1.0000000000
Number of Vertices : 59997
Number of Faces : 119990
29.4696752463 12.6605791420 30.6919154781
29.1161389891 13.2225081759 30.8961547223
25.8970270085 17.1671635879 32.5284062521
25.3111418518 16.7610352994 32.0368219549
27.4993616759 13.8120514401 30.4372772554
20.8197376962 18.3168655883 31.3811258705
7147 7401 7402
7403 7147 7402
7403 7402 7404
7403 7404 7405
7406 7403 7405
7406 7405 7150
------------------------------
and my programme is this......
Expand|Select|Wrap|Line Numbers
  1. struct GLpoint {
  2.     float x, y, z;
  3.     };
  4. GLpoint OBJ_VERTICES[30];
  5.  
  6. struct GLFace {
  7.     unsigned short v1, v2, v3;
  8. };
  9.  
  10.  
  11. int cnt = 0;
  12. int nb_Faces = 0;
  13.  
  14.  
  15.  
  16. int main()
  17. {
  18.         string line;
  19.         fstream file_op("c:\\temp2.txt", ios::in);
  20.  
  21.         if (!file_op)
  22.             return false;
  23.         else 
  24.         {
  25.             do
  26.             {
  27.                     getline(file_op,line);
  28.                     getline(file_op,line);
  29.                     getline(file_op,line);
  30.                     getline(file_op,line);
  31.                     getline(file_op,line);
  32.                     getline(file_op,line);
  33.                     getline(file_op,line);
  34.                     getline(file_op,line);
  35.                     getline(file_op,line);
  36.                     file_op >> OBJ_VERTICES[nb_Faces].x >> OBJ_VERTICES[nb_Faces].y >> OBJ_VERTICES[nb_Faces].z;
  37.                     nb_Faces++;
  38.             }while(!file_op.eof());
  39.             cout<<" \n\tno of lines = "<<nb_Faces<<endl;
  40.             cout<<OBJ_VERTICES[nb_Faces].x<<"    " << OBJ_VERTICES[nb_Faces].y<<"   " << OBJ_VERTICES[nb_Faces].z;
  41.             return true;            
  42.         }
  43. }
Nov 5 '07 #1
18 5851
sicarie
4,677 Expert Mod 4TB
luckyyyyyy-

It is extremely rude to hijack someone else's thread, especially when you don't use code tags or anything else. I will split it off this time, but read through our Posting Guidelines, and follow them if you want to use this site.
Nov 5 '07 #2
sicarie
4,677 Expert Mod 4TB
I appriate your work but...
guys i have another problm.....i wana skip first 9 lines from my data file and after skipping i wana read x,y,z at the end of file. i did but after while loop is end it again skip these 9 lines. how to solve this.
Keep 9 lines in buffer (don't print them out or manipulate them), and then check for eof.
and also i wana distinguish these float data and unsigned data, as you can see in data file. after 9 lines, 6 lines are the float data, after this 6 lines are unsigned int.
You can parse lines with strtok()
Nov 5 '07 #3
Keep 9 lines in buffer (don't print them out or manipulate them), and then check for eof.

You can parse lines with strtok()


thanks.....

and yes i got it...the right code is this...
full code removed---------------------
but how to distiguish float and int values in this data...i want to store float values in GLpoint struct...and int values in GLface struct.......when it read it makes no any difference to float and int..
for example...
if (the end of float value)
then
read the int values and store in GLface struct...
Nov 5 '07 #4
sicarie
4,677 Expert Mod 4TB
You can parse lines with strtok()
What's in the float's that's not in the ints?
Nov 5 '07 #5
thanks.....

and yes i got it...the right code is this...
full code removed---------------------
but how to distiguish float and int values in this data...i want to store float values in GLpoint struct...and int values in GLface struct.......when it read it makes no any difference to float and int..
for example...
if (the end of float value)
then
read the int values and store in GLface struct...
--------------------------------------------------------------
i dont know what i did wrong to post my question...i read your posting guidline but i couln't find, just two r three things, its should be capital letter, its just my third post...ok i will try my best..
Nov 5 '07 #6
--------------------------------------------------------------
i dont know what i did wrong to post my question...i read your posting guidline but i couln't find, just two r three things, its should be capital letter, its just my third post...ok i will try my best..
--------
ok i explain...

this is the data...

29.4696752463 12.6605791420 30.6919154781
29.1161389891 13.2225081759 30.8961547223
25.8970270085 17.1671635879 32.5284062521
25.3111418518 16.7610352994 32.0368219549
27.4993616759 13.8120514401 30.4372772554
20.8197376962 18.3168655883 31.3811258705
7147 7401 7402
7403 7147 7402
7403 7402 7404
7403 7404 7405
7406 7403 7405
7406 7405 7150

first six lines have values float x,y,z, . and last six has unsigned int fx,fy,fz...I wana store first six in x,y,z, and last six in fx,fy,fz. when reading this file...how to do this...i think there should be a if command....if (float vaues) then this....if(int value) then this...
Nov 5 '07 #7
sicarie
4,677 Expert Mod 4TB
--------------------------------------------------------------
i dont know what i did wrong to post my question...i read your posting guidline but i couln't find, just two r three things, its should be capital letter, its just my third post...ok i will try my best..
You hijacked someone else's thread - I split it off. You did not use code tags, I filled them in for you. Thank you for reading the Guidelines, please follow them in your future posts.
Nov 5 '07 #8
sicarie
4,677 Expert Mod 4TB
--------
ok i explain...

first six lines have values float x,y,z, . and last six has unsigned int fx,fy,fz...I wana store first six in x,y,z, and last six in fx,fy,fz. when reading this file...how to do this...i think there should be a if command....if (float vaues) then this....if(int value) then this...
Okay, so is it like that every time? Can you ahrd code the first 6 to be floats and the last six to be unsigned ints?

If not, then you have to look for patterns in the data. You can read text in different ways, I'm suggesting to read it in as a string and parse the string for something that the floats have that the unsigned ints don't. From there, you can do whatever you want with it - you have your if condition that will report true or false.
Nov 5 '07 #9
You hijacked someone else's thread - I split it off. You did not use code tags, I filled them in for you. Thank you for reading the Guidelines, please follow them in your future posts.
-----------------
i hijacked someone else's thread...whats the meaning of hijack...really i dont know what i did wrong...may be "title is change" that's why...but i dont know...please ignor my mistake... thanks
Nov 5 '07 #10
sicarie
4,677 Expert Mod 4TB
You posted your question in someone else's thread, trying to change the focus from their problem (that started the thread and built the responses) to yours. It's not a huge deal, but it is considered rude - which is why we ask people not to do it.
Nov 5 '07 #11
You posted your question in someone else's thread, trying to change the focus from their problem (that started the thread and built the responses) to yours. It's not a huge deal, but it is considered rude - which is why we ask people not to do it.
-----
ok I understand now what i did wrong....

but i could't understand what your mean ...read text with string then parse it...how these data reading is very easy ....i read all this file ...it has 1 millions lines...but problem is how to make a diffirence in float values mean vertices of triangles......and int values means faces of triangles....
Nov 5 '07 #12
sicarie
4,677 Expert Mod 4TB
You are using getline() in your program, what does getline() return? What format is that data in?
Nov 5 '07 #13
for example
Expand|Select|Wrap|Line Numbers
  1.             do
  2.             {
  3.                     file_op >> OBJ_VERTICES[nb_Faces].x >> OBJ_VERTICES[nb_Faces].y >> OBJ_VERTICES[nb_Faces].z;
  4.                     nb_Faces++;
  5.             }while(!file_op.eof());
  6.             for (int i=0; i<nb_Faces; i++)
  7.             cout<<OBJ_VERTICES[i].x<<"    " << OBJ_VERTICES[i].y<<"   " << OBJ_VERTICES[i].z<<endl;
  8.  
--------------------------------
when read this data file....nb_Faces will be increas and increas...suppose its value is near to 50,000, means 50,000 line no. Now from here start the faces information....and from here i want to store these value in another variable or structure....how to do this
Nov 5 '07 #14
[quote=luckyyyyyy][quote=luckyyyyyy]-----
this is the data,,...i have already posted it but ok..

#Version 1.0
Shell type : GENERIC
Projection Matrix
1.0000000000 0.0000000000 0.0000000000 0.0000000000
0.0000000000 1.0000000000 0.0000000000 0.0000000000
0.0000000000 0.0000000000 1.0000000000 0.0000000000
0.0000000000 0.0000000000 0.0000000000 1.0000000000
Number of Vertices : 59997
Number of Faces : 119990
29.4696752463 12.6605791420 30.6919154781
29.1161389891 13.2225081759 30.8961547223
25.8970270085 17.1671635879 32.5284062521
25.3111418518 16.7610352994 32.0368219549
27.4993616759 13.8120514401 30.4372772554
20.8197376962 18.3168655883 31.3811258705
7147 7401 7402
7403 7147 7402
7403 7402 7404
7403 7404 7405
7406 7403 7405
7406 7405 7150
----
this is the data file....getline() mean skiping first 9 lines...i dont want these header lines.....and after these header lines...point data start....ok..now you understand i thnik
Nov 5 '07 #15
sicarie
4,677 Expert Mod 4TB
You just declare the type that you want it to be, as an array, and start loading the data into it. Make a conversion of the data if you need to.

I'm really not sure what you want, as you have now asked 3 different questions claiming that they were the same one. Unless you can specify what you want to do, I am going to suggest you go read more tutorials/books/assignments and come back later.
Nov 5 '07 #16
sicarie
4,677 Expert Mod 4TB
this is the data,,...i have already posted it but ok..
Yes, yes you have. And it still hasn't changed. Nor has my advice.
this is the data file....getline() mean skiping first 9 lines...i dont want these header lines.....and after these header lines...point data start....ok..now you understand i thnik
Right, so you ignore them. How are you reading in the data after that? Just through file_op? If you know how many lines are of each type, you can declare and use the proper type (float or int). If you don't, you need to read them in (using getline()), and parse them for the period, which will signify that one is a float. If it is a float, you can use atof(), if not, you can use atoi(). And you have your data.
Nov 5 '07 #17
Yes, yes you have. And it still hasn't changed. Nor has my advice.

Right, so you ignore them. How are you reading in the data after that? Just through file_op? If you know how many lines are of each type, you can declare and use the proper type (float or int). If you don't, you need to read them in (using getline()), and parse them for the period, which will signify that one is a float. If it is a float, you can use atof(), if not, you can use atoi(). And you have your data.
-------------------------
i think you could't understand my problm...ok i try make it easy...
ok
if we have these two structure..
struct GLpoint {
GLfloat x, y, z;
};


struct GLFace {
unsigned short v1, v2, v3;
};
and
GLpoint OBJ_VERTICES [] = {

{(float)54.111641, (float)-0.007899, (float)37.141083},
{(float)55.552414, (float)-5.571973, (float)41.828125},
{(float)53.201775, (float)-9.007742, (float)47.965961},
---------
----------
-----
GLFace OBJ_FACES[] = {
{0, 11, 12},
{0, 12, 1},
{1, 12, 13},
------
-------
-----bla bla bla...

if we use this kind of code then its very easy....but we have these array values in text file...if we want only one type mean only GLpoint OBJ_VERTICES [] this..then its very easy but in text file ..after the end of {(float)54.111641, (float)-0.007899, (float)37.141083}, these info...start {0, 11, 12},
{0, 12, 1},
{1, 12, 13}, these values...like this..
this is a text file...
25.3111418518 16.7610352994 32.0368219549
27.4993616759 13.8120514401 30.4372772554
20.8197376962 18.3168655883 31.3811258705 ( how to stop here) and then
7147 7401 7402 read this line and store in GLFace OBJ_FACES[] ..
7403 7147 7402
7403 7402 7404
----
Nov 5 '07 #18
sicarie
4,677 Expert Mod 4TB
-------------------------
i think you could't understand my problm...ok i try make it easy...
And I'm done. If you can't look at what I'm saying and realize I have directly told you the answer to your problem, I cannot help you.

I realize that you are trying to figure out where one datatype ends. I have told you two methods of doing so. You have not answered my questions as to the fixed size of the data set (or not), so I cannot tell you which will work. The getline()/strtok() will work in all cases, and I would recommend that, but you still can't see how so I'm wasting my time.

In the future, I would suggest reading and playing with code much more than you are doing now. It will broaden your understanding so that when people tell you how you can fix your code, you will then be able to do so.
Nov 5 '07 #19

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Pjotr Wedersteers | last post: by
3 posts views Thread by puzzlecracker | last post: by
16 posts views Thread by Adam Witney | last post: by
15 posts views Thread by eight02645999 | last post: by
2 posts views Thread by odin607 | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.