Click here to Skip to main content
15,903,033 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Count Character in string Pin
Cedric Moonen20-Nov-07 20:19
Cedric Moonen20-Nov-07 20:19 
GeneralRe: Count Character in string Pin
manish.patel20-Nov-07 20:45
manish.patel20-Nov-07 20:45 
GeneralRe: Count Character in string Pin
Cedric Moonen20-Nov-07 20:55
Cedric Moonen20-Nov-07 20:55 
GeneralRe: Count Character in string Pin
manish.patel20-Nov-07 21:03
manish.patel20-Nov-07 21:03 
GeneralRe: Count Character in string Pin
KarstenK20-Nov-07 21:04
mveKarstenK20-Nov-07 21:04 
GeneralRe: Count Character in string Pin
manish.patel20-Nov-07 21:13
manish.patel20-Nov-07 21:13 
GeneralRe: Count Character in string Pin
Cedric Moonen20-Nov-07 21:44
Cedric Moonen20-Nov-07 21:44 
GeneralRe: Count Character in string (even faster) Pin
bolivar12321-Nov-07 3:06
bolivar12321-Nov-07 3:06 
<br />
typedef unsigned char BYTE;<br />
<br />
int countByte(BYTE *src, BYTE b)<br />
{<br />
   int count = 0;<br />
   BYTE *s;<br />
   for (s=src;*s; s++)<br />
     if (*s == b)<br />
       count++;<br />
   return count;<br />
} <br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
	char s[20] = "111222333";<br />
	//Count the # of 1's in string s<br />
	printf("%d",countByte((BYTE*)s,'1'));<br />
	return 0;<br />
}<br />


This version eliminates the strlen call and it eliminates the use of the square brackets []. Each time you use the square bracket array index, an offset into your array has to be calculated.
QuestionCWnd Pin
kk.tvm20-Nov-07 19:07
kk.tvm20-Nov-07 19:07 
AnswerRe: CWnd Pin
Hamid_RT20-Nov-07 19:11
Hamid_RT20-Nov-07 19:11 
GeneralRe: CWnd Pin
kk.tvm20-Nov-07 21:11
kk.tvm20-Nov-07 21:11 
GeneralRe: CWnd Pin
Hamid_RT20-Nov-07 21:18
Hamid_RT20-Nov-07 21:18 
QuestionHow to SetWindowPos correctly? Actually confused with GetClientRect,GetWindowRect,ScreenToClient and ClientToScreen etc. Pin
fantasy121520-Nov-07 18:36
fantasy121520-Nov-07 18:36 
AnswerRe: How to SetWindowPos correctly? Actually confused with GetClientRect,GetWindowRect,ScreenToClient and ClientToScreen etc. Pin
Mark Salsbery20-Nov-07 19:01
Mark Salsbery20-Nov-07 19:01 
GeneralRe: How to SetWindowPos correctly? Actually confused with GetClientRect,GetWindowRect,ScreenToClient and ClientToScreen etc. [modified] Pin
fantasy121520-Nov-07 20:34
fantasy121520-Nov-07 20:34 
GeneralRe: How to SetWindowPos correctly? Actually confused with GetClientRect,GetWindowRect,ScreenToClient and ClientToScreen etc. Pin
Parthi_Appu21-Nov-07 0:25
Parthi_Appu21-Nov-07 0:25 
QuestionRe: How to SetWindowPos correctly? Actually confused with GetClientRect,GetWindowRect,ScreenToClient and ClientToScreen etc. [Understood clearly] Pin
fantasy121521-Nov-07 13:59
fantasy121521-Nov-07 13:59 
GeneralRe: How to SetWindowPos correctly? Actually confused with GetClientRect,GetWindowRect,ScreenToClient and ClientToScreen etc. Pin
Mark Salsbery21-Nov-07 5:15
Mark Salsbery21-Nov-07 5:15 
QuestionGetWindowText in OnKeyDown not correct Pin
followait20-Nov-07 18:26
followait20-Nov-07 18:26 
AnswerRe: GetWindowText in OnKeyDown not correct Pin
Hamid_RT20-Nov-07 18:35
Hamid_RT20-Nov-07 18:35 
GeneralRe: GetWindowText in OnKeyDown not correct Pin
followait20-Nov-07 18:40
followait20-Nov-07 18:40 
AnswerRe: GetWindowText in OnKeyDown not correct Pin
Haroon Sarwar20-Nov-07 18:36
Haroon Sarwar20-Nov-07 18:36 
GeneralRe: GetWindowText in OnKeyDown not correct Pin
followait20-Nov-07 18:40
followait20-Nov-07 18:40 
AnswerRe: GetWindowText in OnKeyDown not correct Pin
fantasy121520-Nov-07 18:42
fantasy121520-Nov-07 18:42 
Questiontchar to constant char mfc-vc++ Pin
Paulraj G20-Nov-07 17:46
Paulraj G20-Nov-07 17:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.