Answer the question
In order to leave comments, you need to log in
Why is extra information written to char (C++)?
So there is a structure
struct userInfo{
char uCardNum[16];
char uPIN[4];
float uBalance;
};
void add(char CN[16],char PIN[4],float Balance){
userInfo ui;
strcpy(ui.uCardNum,CN);
strcpy(ui.uPIN,PIN);
ui.uBalance=Balance;
users.push_back(ui);
printf(ui.uCardNum);
};
Answer the question
In order to leave comments, you need to log in
Actually, the functions "strcpy(ui.uCardNum,CN); strcpy(ui.uPIN,PIN);" do not work correctly for you and can lead to the crash of the program due to damage to the stack. In debugging, the compiler can even swear at this. These strings copy characters from one string to another until a null terminator is encountered in the source string, and you don't have a null terminator anywhere. Theoretically, at least gigabytes of garbage can be copied in these places ...
As already mentioned, you either need to do a null terminator at the end of the lines (but this will increase the size of each line by one character), or output these lines not as a string, but through a format string , character by character.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question