|
Hi,
You will probably need to derive a class from CIPAddressCtrl and handle the WM_CTLCOLOR message and return a BRUSH with the color of your choice.
Best Wishes,
-David Delaune
|
|
|
|
|
Hi,
add handler for WM_CTLCOLOR, then check for CTLCOLOR_EDIT and use SetBkColor(RGB());
|
|
|
|
|
how to read a string character by character in C?
|
|
|
|
|
In C, a string is simply an array of characters.
So to read each character you simply index into the array -
char arr[10];
arr[0];
arr[9];
|
|
|
|
|
char str[10]="hghghhj"
int i;
for(i=0;i<10;i++)
printf("%c",str[i]);
|
|
|
|
|
robin700 wrote: how to read a string...
This is very ambiguous. Read a string from where?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Read from what?
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]
|
|
|
|
|
i have a character array such that
char buffer[]= "bob 12345"
and text file has the data
bob 12345
mike abcde
easton 9999
now i want to compare the array with the file line by line and find whether a valid combination of usernames and passwords exist....
please help
|
|
|
|
|
Read the file line by line (fgets ) and compare with buffer (strcmp ).
|
|
|
|
|
Didn't you just ask this question here?
So which part exactly are you needing help with? Iterating a file, text comparison, or something else?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
|
I have a vector string array filled as follows:
"s1" "v1" "s1" "f1" "g1" "s1" "s1" "o1"
so the result has to be "s1 4". I have to write the string value and the num value in strArtist and iNum. How's that?
void maxCollByArtist(string& strArtist, int& iNum)
{
int max = 0;
string t_str = "";
vector<string> temp;
for(int i = 0; i < m_vMusic.size(); i++)
temp[i] = m_vMusic[i].GetArtist();
for(int i = 0; i < temp.size(); i++)
{
}
}
|
|
|
|
|
if you sort the vector, identical items will be next to each other so it will be simpler to count which of them repeats the most
|
|
|
|
|
I did it. Now how to see which element repeats the most and how many times? (Created a new project)
int main()
{
string str[8] = {"zxc", "zxc", "asd", "qwe", "zxc", "asd", "qwe", "jkl"};
vector<string> v_str;
string t_str;
int iNum = 0;
for(int i = 0; i < 8; i++)
v_str.push_back(str[i]);
for(int i = 1; i < v_str.size(); i++)
for(int j = v_str.size() - 1; j >= i; j--)
if(v_str[j - 1] > v_str[j])
{
t_str = v_str[j - 1];
v_str[j - 1] = v_str[j];
v_str[j] = t_str;
}
for(int i = 0; i < v_str.size(); i++)
cout << v_str[i] << endl;
return 0;
}
|
|
|
|
|
or, just use:
std::sort(v_str.begin(), v_str.end())
so if you have a sorted list of strings:
aaa, aaa, bb, cc, ccc, dd, dd, dd, dd, e, f, g
iterate through the list, check to see when the current item is equal to the last item. if it's the same, keep track of how many times it repeats. if it's different, see if the number of repetitions was greater than the max number of reps you've seen so far.
cur = vec[0]
maxrep = 1
maxstring = cur
currep = 1
for each item in vec, starting at vec[1]
if item==cur
currep++ // we have a repeat, keep track of how many repetitions
else
// the strings are different,
if currep > maxrep // was this repetition count higher than the max
maxrep=currep // it is the new max
maxstring=cur
cur=item // next item is current
currep = 0
|
|
|
|
|
It's not working. Gives me "zxc" and 1, but the correct is "qwe" and 3.
int main()
{
string str[8] = {"zxc", "zxc", "asd", "qwe", "qwe", "asd", "qwe", "jkl"};
vector<string> v_str;
string t_str, maxstring;
int maxrep = 1;
int currep = 1;
for(int i = 0; i < 8; i++)
v_str.push_back(str[i]);
for(int i = 1; i < v_str.size(); i++)
for(int j = v_str.size() - 1; j >= i; j--)
if(v_str[j - 1] > v_str[j])
{
t_str = v_str[j - 1];
v_str[j - 1] = v_str[j];
v_str[j] = t_str;
}
t_str = v_str[0];
maxstring = t_str;
for(int i = 1; i < v_str.size(); i++)
{
if(v_str[i] == t_str)
currep++;
else if(currep > maxrep)
{
maxrep = currep;
maxstring = t_str;
}
t_str = v_str[i];
currep = 0;
}
for(int i = 0; i < v_str.size(); i++)
cout << v_str[i] << endl;
cout << endl;
cout << t_str << endl;
cout << maxrep << endl;
return 0;
}
|
|
|
|
|
else if(currep > maxrep)
{
maxrep = currep;
maxstring = t_str;
}
t_str = v_str[i];
currep = 0;
should be:
else
{
if(currep > maxrep)
{
maxrep = currep;
maxstring = t_str;
}
t_str = v_str[i];
currep = 0;
}
also, you will have to add a check after the loop, to see if the last repetition has not ended.
|
|
|
|
|
" to see if the last repetition has not ended."
what does that mean?
|
|
|
|
|
Here is my code, but it shows "asd 2" instead of "qwe 3". Why is that?
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
string str[8] = {"zxc", "zxc", "asd", "qwe", "qwe", "asd", "qwe", "jkl"};
vector<string> v_str;
string t_str, maxstring;
int maxrep = 1;
int currep = 1;
for(int i = 0; i < 8; i++)
v_str.push_back(str[i]);
sort(v_str.begin(), v_str.end());
t_str = v_str[0];
maxstring = t_str;
for(int i = 1; i < v_str.size(); i++)
{
if(t_str == v_str[i])
currep++;
else
{
if(currep > maxrep)
{
maxrep = currep;
maxstring = t_str;
}
t_str = v_str[i];
currep = 0;
}
}
for(int i = 0; i < v_str.size(); i++)
cout << v_str[i] << endl;
cout << endl;
cout << maxstring << " " << maxrep << endl;
return 0;
}
|
|
|
|
|
TCPMem wrote: currep = 0;
i suspect it's because you're setting currep = 1, the first time, but 0 all the other times. the first set of matches will have a higher rep count than the others.
|
|
|
|
|
TCPMem wrote: I did it. Now how to see which element repeats the most and how many times?
TCPMem,
Rather than re-inventing those algorithms... just use the ones supplied by the c++ language.
string str[8] = {"zxc", "zxc", "asd", "qwe", "zxc", "asd", "qwe", "jkl"};
vector<string> v_strAll;
vector<string> v_strUnique;
list<pair<string,size_t>> counts;
v_strAll.assign(str,str+_countof(str));
sort(v_strAll.begin(),v_strAll.end());
unique_copy(v_strAll.begin(),v_strAll.end(),back_inserter(v_strUnique));
std::vector<string>::iterator it = v_strUnique.begin();
while(it != v_strUnique.end())
{
counts.push_back(make_pair(*it,count_if(v_strAll.begin(),v_strAll.end(),[it](const std::string& s1){return s1 == *it;})));
++it;
}
Heh, if you really want to annoy the guy reviewing your code... you can get rid of that while loop and use a dual lambda if your compiler supports it.
for_each(v_strUnique.begin(),v_strUnique.end(),[&counts,v_strAll](const std::string& str){counts.push_back(make_pair(str,count_if(v_strAll.begin(),v_strAll.end(),[str](const std::string& s1){return s1 == str;})));});
|
|
|
|
|
+5 for the last bit. And here I was thinking that APL and Perl were the only write-only languages (not counting obscurities like Brainf*ck).
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
please tell me how can i read a data file into an array line by line
for e.g i have
bob 123
mike 456
|
|
|
|
|
use CStdioFile and CStdioFile::ReadString to read one file, and a nice while loop to read each line; put each line that you read into a std::vector<CString > .
If you need to split each line into section (name and number), then you will need to use something like strtok .
goood luck.
Watched code never compiles.
|
|
|
|
|
Using just stl you can do something like:
ifstream file("file.dat");
vector<string> lines;
string line;
while (getline(file, line))
lines.push_back(line);
|
|
|
|