| | |
find string in txt file
![]() |
•
•
Join Date: May 2008
Posts: 99
Reputation:
Solved Threads: 1
ok so im trying to find a certain string in a txt file and once its found it needs to skip that line, the next line then add the following 2 lines into their own buffers.
EG:
Example ofomgwtfcantfindit kthx
Woot
Bang
asdasd
'asdasd
asdasd
so it finds the string "ofomgwtfcantfindit then it would skip that line, the blank line under it and add Woot to buffer1 and Bang to buffer2.
anyone have any ideas
EG:
Example ofomgwtfcantfindit kthx
Woot
Bang
asdasd
'asdasd
asdasd
so it finds the string "ofomgwtfcantfindit then it would skip that line, the blank line under it and add Woot to buffer1 and Bang to buffer2.
anyone have any ideas
•
•
Join Date: May 2008
Posts: 99
Reputation:
Solved Threads: 1
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <string> using namespace std; int main() { ifstream RapidShit ("C:\\Rapid.txt"); string ****Nipples; if(RapidShit.is_open()) { while (! RapidShit.eof() ) { getline(RapidShit, ****Nipples); if(****Nipples == "asdasdasd") { // how to skip 2 lines and get the other 2 into the buffers } } } cin.get(); return 0; }
>>string ****Nipples;
OMG what in hell are you trying to do here??? If you are trying to code an array of string's then its
But the reading part should look like this: (I hope you change the variable names before turning in the assignment because your teacher may not be that humerious.)
OMG what in hell are you trying to do here??? If you are trying to code an array of string's then its
string Nipples[4]; But the reading part should look like this: (I hope you change the variable names before turning in the assignment because your teacher may not be that humerious.)
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <string> #include <vector> using namespace std; int main() { ifstream RapidShit ("C:\\Rapid.txt"); vector<string> Nipples; // an array of strings string line; // one line in the file if(RapidShit.is_open()) { while (getline(RapidShit, line) ) { Nipples.push_back(line); // add to the array } // now you have the entire file in memory. Search each line // for the desired entry. } cin.get(); return 0; }
Last edited by Ancient Dragon; Dec 2nd, 2008 at 8:37 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: May 2008
Posts: 99
Reputation:
Solved Threads: 1
Lol, this isnt for an assignment. I code because i can not because i have to but this is what i have so far.
Just wonder how i can store those First buffer line and Second buffer line in char szBuffer1[50], szBuffer2[50];
Thanks
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <string> using namespace std; char szUser[50], szPass[50]; bool bFound = false; int main() { ifstream RapidShit ("C:\\Rapid.txt"); string ****Nipples; if(RapidShit.is_open()) { while (!bFound) { getline(RapidShit, ****Nipples); cout << ****Nipples << endl; if(****Nipples == "WORD") { getline(RapidShit, ****Nipples); cout << ****Nipples << endl; getline(RapidShit, ****Nipples); // First buffer i need cout << ****Nipples << endl; getline(RapidShit, ****Nipples); // Second cout << ****Nipples << endl; bFound = true; } } } cin.get(); return 0; }
Just wonder how i can store those First buffer line and Second buffer line in char szBuffer1[50], szBuffer2[50];
Thanks
>>string ****Nipples;
Forget about doing that! It won't work. That is not four strings, but a pointer to pointer to pointer to pointer of type string. Amazingly it compiles without error, but that doesn't mean it will work, which it won't.
Forget about doing that! It won't work. That is not four strings, but a pointer to pointer to pointer to pointer of type string. Amazingly it compiles without error, but that doesn't mean it will work, which it won't.
Last edited by Ancient Dragon; Dec 2nd, 2008 at 10:18 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: May 2008
Posts: 99
Reputation:
Solved Threads: 1
oh it works 
Probably far too long but it works.

C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <string> using namespace std; char szUser[50], szPass[50]; bool bFound = false; void GetUser(string szInput) { const char *szUserBuffer; std::string szTemp = szInput; szUserBuffer = szTemp.c_str(); sprintf(szUser, "%s", szUserBuffer); for (int i = strlen(szUser) + 1; i > 0; i--) { if( szUser[i] == ':') { strcpy(szUser, &szUser[i + 2]); break; } } } void GetPassword(string szInput) { const char *szPassBuffer; std::string szTemp = szInput; szPassBuffer = szTemp.c_str(); sprintf(szPass, "%s", szPassBuffer); for (int t = strlen(szPass) + 1; t > 0; t--) { if( szPass[t] == ':') { strcpy(szPass, &szPass[t + 2]); break; } } } int main() { ifstream RapidShit ("C:\\Rapid.txt"); string ****Nipples; if(RapidShit.is_open()) { while (!bFound) { getline(RapidShit, ****Nipples); if(****Nipples == "https://ssl.rapidshare.com") { getline(RapidShit, ****Nipples); getline(RapidShit, ****Nipples); GetUser(****Nipples); getline(RapidShit, ****Nipples); GetPassword(****Nipples); bFound = true; } } } cin.get(); return 0; }
Probably far too long but it works.
>>Probably far too long but it works.
Only because you were very lucky in your tests.
>>getline(RapidShit, ****Nipples);
What does that pointer Nipples point to? Nowhere -- just some random number because Nipples was never initialized.
Only because you were very lucky in your tests.
>>getline(RapidShit, ****Nipples);
What does that pointer Nipples point to? Nowhere -- just some random number because Nipples was never initialized.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Mar 2008
Posts: 1,381
Reputation:
Solved Threads: 112
•
•
•
•
Originally Posted by Ancient Dragon
Amazingly it compiles without error
So I'm not too surprised that his compiled x)
C++ Syntax (Toggle Plain Text)
char ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** a;
Last edited by William Hemsworth; Dec 4th, 2008 at 1:13 pm.
![]() |
Similar Threads
- how to ingrate my code to read txt file in dirctory(folder)and subdirectory? PLZ help (Python)
- Replace a Word in a .txt file (C++)
- school task help (Java)
- Need Help to read .txt file and store its contents (Java)
- Huge flat file (Visual Basic 4 / 5 / 6)
- Need Help in Reading characters from a text file (C++)
- File array question (C++)
- Where can I find examples of scripts? (C++)
- Reading from a file to fill an array (Java)
- Help!! Applet only works in AppletViewer but not in html file with <applet> tags!!! (Java)
Other Threads in the C++ Forum
- Previous Thread: Need help!!!search word from text file and display lines which match the word.
- Next Thread: Using Bubble sort to sort Arrays please help
| Thread Tools | Search this Thread |
action api array auto based beginner binary bitmap c++ c/c++ calculator challenge char class classes code coding compile console conversion count createcopyofanyfileinc delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game garbage givemetehcodez graph gui hmenu homeworkhelp homeworkhelper iamthwee ifstream input insert int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node noob output parameter pointer primenumbersinrange problem program programming project python random read recursion reference rpg sockets string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets






