string operation
-
i have a string such that hello hi good i want to extract the values line by line....please help
What sort of string, and what do you mean by extract the values line by line? You could use one of the strtok[^] variants for a simple character array, or one of these functions[^] for a
string
.Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
What sort of string, and what do you mean by extract the values line by line? You could use one of the strtok[^] variants for a simple character array, or one of these functions[^] for a
string
.Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
i have a character array such thatb char buffer[100]; the values are stored like cklvcmsdl dclcm dcpcc i have to extract these values line by line and compare them with the input to find matching usernames buffer contains the usernames
Well it looks like you need to use the first option I suggested.
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
i have a character array such thatb char buffer[100]; the values are stored like cklvcmsdl dclcm dcpcc i have to extract these values line by line and compare them with the input to find matching usernames buffer contains the usernames
That means the user names are separated by the newline character, you may use
strtok
as Richard already suggested or hand-craft a simple loop to collect all the names.If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
That means the user names are separated by the newline character, you may use
strtok
as Richard already suggested or hand-craft a simple loop to collect all the names.If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]As CPallinial suggested, here is simple loop to collect all the names.
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>using namespace std;
char one_line_string[] = "hello hi how are you nice weather we are having ok then bye";
char seps[] = " ,\t\n";
char *token;int main()
{
vector<string> vec_String_Lines;
token = strtok( one_line_string, seps );cout << "Extracting and storing data in a vector..\n\n\n";
while( token != NULL )
{
vec_String_Lines.push_back(token);
token = strtok( NULL, seps );
}
cout << "Displaying end result in vector line storage..\n\n";for ( int i = 0; i < vec\_String\_Lines.size(); ++i) cout << vec\_String\_Lines\[i\] << "\\n"; cout << "\\n\\n\\n";
return 0;
}