Note that there are some explanatory texts on larger screens.

plurals
  1. POStack around variable corrupted? C
    primarykey
    data
    text
    <p>I have 2 issues, but this is the more pressing one...</p> <pre><code>printf("Enter the term: "); scanf("%d", &amp;input); fprintf(inputf, "%d,", input); printf("Enter the id: "); scanf("%d", &amp;input); fprintf(inputf, "%d,", input); printf("Enter last name: "); scanf("%s", name); fprintf(inputf, "%s,", name); printf("Enter first name: "); fgets(name, 15, stdin); fprintf(inputf, "%s,", name); printf("Enter the subject: "); scanf("%s", subsec); fprintf(inputf, "%s,", subsec); printf("Enter the catalog number: "); scanf("%d", &amp;input); fprintf(inputf, "%d,", input); //ISSUE HERE! printf("Enter the section: "); scanf("%s", subsec); fprintf(inputf, "%s\n", subsec); </code></pre> <p>Whenever I input all of this information and press enter on the last variable entry I get a window that says this "Run-Time Check Failure #2 - Stack around the variable 'subsec' was corrupted." I can continue and the program pretty much does what I want it to and works, but why is this happening?</p> <p>My second part is when I get to entering the last name, and then want to enter the first name, it takes in the "\n" character when I press enter for the firstname string variable, obviously dont want that happening, but the both first and last name need to be capable of holding strings with whitespaces. How do I kill both birds with a single stone? I used fget to allow me to hold whitespace, but it cases my "\n" capture issue, but if I change it back to scanf, I cant hold whitespaces!</p> <p>EDIT: This is subsec</p> <pre><code>char subsec[MAX_SUBSEC]; </code></pre> <p>MAX_SUBSEC is set to three, I use it previously as you can see, but I figured the second scanf (the one for section, not subject) would write over the original use of inputting subsec, Im going to say I am wrong? And I am not allowed to do this, thus the issue...</p> <p>Input for subject will be "CSE" and the input for section will be "R01" And yes this is all going to be put into a file.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload