Click here to Skip to main content
15,897,371 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: String error again! Help plz Pin
Jonathan Craig15-May-02 7:24
Jonathan Craig15-May-02 7:24 
GeneralRe: String error again! Help plz Pin
Joaquín M López Muñoz15-May-02 5:21
Joaquín M López Muñoz15-May-02 5:21 
GeneralRe: String error again! Help plz Pin
tongc15-May-02 6:21
tongc15-May-02 6:21 
GeneralMemory compareing with char's Pin
SilverShalkin15-May-02 4:07
SilverShalkin15-May-02 4:07 
GeneralRe: Memory compareing with char's Pin
Jason Henderson15-May-02 4:41
Jason Henderson15-May-02 4:41 
GeneralRe: Memory compareing with char's Pin
SilverShalkin15-May-02 4:55
SilverShalkin15-May-02 4:55 
GeneralRe: Memory compareing with char's Pin
SilverShalkin15-May-02 5:02
SilverShalkin15-May-02 5:02 
GeneralRe: Memory compareing with char's Pin
Jason Henderson15-May-02 5:20
Jason Henderson15-May-02 5:20 
The 32 in strncpy tells the function the number of chars to copy the the string. You don't want it to copy past the bounds of your array.

If you send the function a 40 char string like "0123456789012345678901234567890123456789", it should cut it off at 32.

Here's a little console app to test it:

#include <iostream.h>
#include <string.h>

char Names[21][32];
int NN = 0;

void vSetName(char* NName)
{
	strncpy(Names[NN], NName, 32);
	NN++;
}

void main()
{
	char inp;
	vSetName("testing");
	vSetName("0123456789012345678901234567890123456789");
	cout << Names[0];
	cout << "\r\n";
	cout << Names[1];
	cin >> inp;
}



Like it or not, I'm right.
GeneralRe: Memory compareing with char's Pin
Jason Henderson15-May-02 5:22
Jason Henderson15-May-02 5:22 
GeneralRe: Memory compareing with char's Pin
Joaquín M López Muñoz15-May-02 5:24
Joaquín M López Muñoz15-May-02 5:24 
GeneralRe: Memory compareing with char's Pin
SilverShalkin15-May-02 8:29
SilverShalkin15-May-02 8:29 
GeneralRe: Memory compareing with char's Pin
Joaquín M López Muñoz15-May-02 9:03
Joaquín M López Muñoz15-May-02 9:03 
GeneralProb. to catch the EOF ?! Pin
Fred D.15-May-02 4:02
Fred D.15-May-02 4:02 
GeneralRe: Prob. to catch the EOF ?! Pin
Jeremy Falcon15-May-02 5:22
professionalJeremy Falcon15-May-02 5:22 
GeneralRe: Prob. to catch the EOF ?! Pin
Joaquín M López Muñoz15-May-02 5:17
Joaquín M López Muñoz15-May-02 5:17 
GeneralMultithreading in C++ without MFC Pin
15-May-02 3:19
suss15-May-02 3:19 
GeneralRe: Multithreading in C++ without MFC Pin
Prem Kumar15-May-02 3:45
Prem Kumar15-May-02 3:45 
GeneralRe: Multithreading in C++ without MFC Pin
Nish Nishant15-May-02 3:51
sitebuilderNish Nishant15-May-02 3:51 
GeneralRe: Multithreading in C++ without MFC Pin
Tim Smith15-May-02 4:45
Tim Smith15-May-02 4:45 
QuestionHow can I get and set the keyboard state? Pin
Edwin Geng15-May-02 2:11
Edwin Geng15-May-02 2:11 
AnswerRe: How can I get and set the keyboard state? Pin
Chris Losinger15-May-02 6:46
professionalChris Losinger15-May-02 6:46 
GeneralRe: How can I get and set the keyboard state? Pin
Edwin Geng16-May-02 6:20
Edwin Geng16-May-02 6:20 
GeneralRe: How can I get and set the keyboard state? Pin
Chris Losinger16-May-02 6:42
professionalChris Losinger16-May-02 6:42 
GeneralAnd now,something completely different Pin
nikoladsp15-May-02 1:26
nikoladsp15-May-02 1:26 
GeneralRe: And now,something completely different Pin
Nish Nishant15-May-02 1:50
sitebuilderNish Nishant15-May-02 1:50 

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.