A mistake in C, not finding out why.

Source: Internet
Author: User
Tags stdin

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Int
Main (void)
{
Char str[512];
Char *endpstr;
int N;
struct Struct_num {
int highs[n];
int violate[n];
};

struct Struct_num num;
/* Get n */
scanf ("%d", &n);
GetChar ();

/* Get Height data */
Fgets (str, stdin);

Endpstr = str;
int cur = 0
/* while (ENDPSTR) {*/
/* num.highs[i++] = strtol (Endpstr, &ENDPSTR, 10); */
/* printf ("%d\n", Strtol (Endpstr, &ENDPSTR, 10)); */
;
/* } */

return 0;
}

This code can be compiled through, but, as long as I put 512, replaced by 1024,1022, will get

Segmentation fault (core dumped)

No need for me to input, direct display error OH

If the transfer

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Int
Main (void)
{
Char str[1024];
Char *endpstr;
int N;
struct Struct_num {
int highs[n];
int violate[n];
};
int cur;
struct Struct_num num;
/* Get n */
scanf ("%d", &n);
GetChar ();

/* Get Height data */
Fgets (str, 1024x768, stdin);

Endpstr = str;
cur = 0;
while (ENDPSTR) {
/* num.highs[i++] = strtol (Endpstr, &ENDPSTR, 10); */
printf ("%d\n", Strtol (Endpstr, &ENDPSTR, 10));
/* ; */
}

return 0;
}

The error that will be displayed is:

Bus error (Core dumped)

If you switch to 512, you will be able to compile and pass. Why is this?

A mistake in C, not finding out why.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.