Home > Back-end >  VS2019 according to trigger a breakpoint
VS2019 according to trigger a breakpoint

Time:09-21


# include & lt; Stdio. H>
# include "stdlib. H"
# include & lt; Conio. H>
# include & lt; String. H>

# define MAXVALUE 10000
# define MAXLEAF 30
# define MAXNODE MAXLEAF * 2-1
Typedef struct {
Int weight;
Int the parent;
Int lchild;
Int rchild;
} HNode HuffmanTree [MAXNODE];

Typedef struct codenode {
Char ch; Deposit/* to */symbols
Char * code;/* * to store the corresponding code/
} CodeNode;
Typedef CodeNode HuffmanCode [MAXLEAF];

Void CrtHuffmanTree (HuffmanTree& Ht, int w [], int n) {
Int I, j, m1, m2, x1, x2,
for (i=0; I & lt; 2 * n - 1; I++) {/* ht initialization */
Ht [I]. Weight=0;
Ht [I]. Parent=1;
Ht [I] lchild=1;
Ht [I] rchild=1;
}
for (i=0; I & lt; n; I++)
Ht [I]. [I] weight=w;
for (i=0; I & lt; N - 1; I++) {/* and Huffman tree */
M1=m2=MAXVALUE;
The x1 x2==0;
For (j=0; J & lt; N + I; J++) {
If (ht [j]. Journal of weight & lt; M1 & amp; & Ht [j]. Journal of parent==1) {
M2 equals m1; X2=x1; X1=j;
M1=ht [j]. Journal of weight;
}
Else if (ht [j]. Journal of weight & lt; M2 & amp; & Ht [j]. Journal of parent==1) {
M2=ht [j]. Journal of weight;
X2=j;
}
}
/* will * two merged into one KeZi KeZi tree tree/
Ht [x1]. Parent=n + I; Ht [x2]. Parent=n + I;
Ht [n + I]. Weight=ht [x1]. Weight + ht [x2]. Weight;
Ht [n + I] lchild=x1; Ht [n + I] rchild=x2;
}
}

/* from leaf nodes to root, reverse search for each leaf node corresponding to the symbol Huffman encoding */
Void CrtHuffmanCode (HuffmanTree ht, HuffmanCode& Hc, int n) {
Char * CD;
Int I, c, p, start;
CD=(char *) malloc (n * sizeof (char));/* to the current workspace allocation */
CD] [n - 1='\ 0';
Printf (" please input in order to be coded character: \ n ");
for (i=0; I & lt; n; I++) {
Start=n - 1;
C=I; P=ht [I] the parent;
while (p !=1) {
If (ht [p]. Lchild==c) CD [-- start]='0';
The else CD [-- start]='1';
C=p; P=ht [p]. The parent;
}
Hc [I]. Code=(char *) malloc ((n - start) * sizeof (char));/* for the ith encode spatial distribution */
fflush(stdin);
Scanf_s (" % c ", & amp; (hc [I] ch));
Strcpy_s (hc [I] code, 10, & amp; CD (start));
}
Free (CD);
}

Int main () {
HuffmanTree ht.
Int a w [MAXLEAF], I, n.
HuffmanCode hc.
Printf (" please enter the number of leaf nodes: ");
Scanf_s (" % d ", & amp; N);
Printf (" please input weights in turn: \ n ");
for (i=0; I & lt; n; I++)
Scanf_s (" % d ", & amp; W [I]);
CrtHuffmanTree (ht, w, n);
CrtHuffmanCode (ht, hc, n);
Printf (" Huffman encoding results for: \ n ");
for (i=0; I & lt; n; I++)
Printf (" % c, % s \ n ", hc [I] ch, hc [I] code);
}


Tried it with dev... Run successfully... Don't know where is wrong... Thank you bosses for help

CodePudding user response:

Copy down ran under no problem ah, vs2019 environment

CodePudding user response:

Application memory is too big, not to come out, the assertion?

CodePudding user response:

reference 1st floor light bamboo hat reply:
copy down ran under no problem ah, environmental vs2019

Aye? I am 2019... According to the... Try several times for no reason

CodePudding user response:

refer to the second floor Qlaiaqu response:
application memory is too big, for not to come out, the assertion?

what should I do that

CodePudding user response:

Bumps, such as a big response

CodePudding user response:

I also ran out no problem, 2019 and 2017 have tried

CodePudding user response:

The
reference 6 floor lights to reply:
I also ran out no problem, 2019 and 2017 have tried

my classmates and I try to is the same problem

CodePudding user response:

refer to 7th floor XXQ の ngc2237 response:
my classmates and I try to is the same problem

1, first of all, if scanf_s reads a character or string, you need to specify the size of the receive address, avoid scanf_s read number greater than the size of the receive buffer, write to write memory address, which is with _s and without _s difference, it is a safe security, but the premise of course still need a programmer to cooperate, so please don't ignore the compiler warnings,
So the changes are as follows:
 scanf_s (" % c ", & amp; Hc [I]. Ch, sizeof (hc [I] ch)); 

2, the second, strcpy_s or similar problems, this function will source buffer content of the string copied to the target buffer, until the source buffer string '\ 0', or copy bytes is greater than or equal to a given user target buffer size (is why Microsoft _s series function, one more parameters, is used to specify the target buffer size),
It is important to note here:
A, the size of the target buffer needs to be enough to hold at the end of the '\ 0',
B, if the size of the target buffer is insufficient, the program will directly abnormal exit in the debug mode, the program will assert error,
C, if the user to specify the size of the actual larger than the size of the target buffer (you actually apply for the 5, but specifies the 10), it will lose _s effect, just like without _s, overflow the risk, once this happens (copy the source buffer too much content to the target buffer, write to write memory address), you have completely lost control of the program, the program collapse immediately but is in the best case _s versions (which is also do), although most afraid of is the program did not collapse, but changed to write content, next, at any time are likely to cause abnormal, screening problem is very difficult, is the problem you met in the current,
You made a mistake, c you fixed to the size of the 10 bytes,
 strcpy_s (hc [I] code, 10, & amp; CD (start)); 

You should change to be like this:
 strcpy_s (hc [I] code, n - start, & amp; CD (start)); 

It is true that you give the input samples, number of input nodes is 5, that is to say, n - start can't be greater than 5, will be smaller than 10, but you can't know strcpy_s it will take you to the 10 to hc [I] what code do SAO operation? Can you know is your hc [I] code content of the buffer size must be n - start,
nullnullnullnullnullnullnull
  • Related