2014-01-30 25 views
1
void Test(Packets& packet) 
{ 
     char buf[BUFLEN]; 
     char* offset = buf; 
     unsigned int foo; 
     for(;!gzeof(file_handle);){ 
      int len = gzread(file_handle, offset, sizeof(buf)-(offset-buf)); 
      char* cur = buf; 
      char* end = offset+len; 
      for (char* eol; (cur<end) && (eol = std::find(cur, end, '\n')) < end; cur = eol + 1) 
      { 
       string string_array = string(cur, eol); 
       if(string_array[0] == 'L'){ 
        packet.foo = blah; 
       }else{ 
        packet.foo = bar; 
       } 
       //After readnig a line.. how do I make sure it quits this function (does another job in some other function) and continous from the next line? 
      } 
#ifdef ROTATION 
     offset = std::rotate(buf, cur, end); 
#else 
     offset = buf + (end-cur); 
     std::rotate(buf, cur, end); 
#endif 
    } 
    std::cout<<std::string(buf, offset) ; 
} 

在readnig一行之後..我如何確保它退出此函數(在其他函數中執行另一個工作)並且從下一行繼續? 我試圖使buf,偏移作爲全局變量,並只在緩衝區爲空時讀取文件..它仍然不起作用。使用C++尋求文件

回答

1

爲什麼要退出該功能並從下一行繼續?

改變你的函數,一個讀取一行的方式,另一種則無論用它

地方你可能想這樣做還是我錯了?

{ 
Packets myPacket; 
Test(packet); 
OtherFunction(packet); 
} 
+0

這是遺留代碼..改變這將是艱難的。 – pistal

+0

好 - 那麼你可以在哪裏做出改變?只是在函數Test()中? – beardedN5rd

+0

是的,只是那個 – pistal