Home > Back-end >  Help!!!!!! C language simple problem * * * stack smashing detected * * * : <unknown> terminate
Help!!!!!! C language simple problem * * * stack smashing detected * * * : <unknown> terminate

Time:03-12

# include & lt; Stdio. H>
# include & lt; Stdlib. H>
# include & lt; String. H>
/* asked to write a program into the student's name, birth year, month, day.
Finally input the name of a student output of TA was born in the year which day */
Typedef struct student {
Char name [30].
Int year;
Int the month;
Int the date;
} Stu.
During the int Isleap (int) {//judgment leap year
If (year %==0 100 & amp; & Year % 400!=0)
return 0;
If (year % 4==0 & amp; & Year % 100!=0)
return 1;
If (year % 4!=0) return 0;
If (year %==0 400) return 1;
}
During the int howmanyDay (int, int the month, int the date) {//calculation and
Int sum=0;
The switch (month) {
Case 1: the sum=date; break;
Case 2: sum=31 + date; break;
Case 3: the sum=59 + Isleap (year) + date; break;
Case 4: sum=90 + Isleap (year) + date; break;
Case 5: sum=120 + Isleap (year) + date; break;
Case 6: sum=151 + Isleap (year) + date; break;
Case 7: sum=181 + Isleap (year) + date; break;
Case 8: sum=212 + Isleap (year) + date; break;
Case 9: sum=243 + Isleap (year) + date; break;
Case 10: sum=273 + Isleap (year) + date; break;
Case 11: sum=304 + Isleap (year) + date; break;
Case 12: sum=334 + Isleap (year) + date; break;
}
Return the sum.


}
Int main ()
{
int n;
The scanf (" % d ", & amp; N);//a total of how many sets of data
Stu Stu [n].
int i;

for(i=0; iThe scanf (" % s % d % d % d ", stu [I]. Name, & amp; Stu [I]. Year, & amp; Stu [I]. The month, & amp; Stu [I] date);//data entry
}
Char c [10];
The scanf (" % s ", c);
for(i=0; iIf (STRCMP (c, stu [I] name)==0) {
Int sum=howmanyDay (stu [I] year, stu [I] month, stu [I] date);
Printf (" % d ", sum);
}
}
return 0;
}
Don't know if I write too much trouble, submitted to the school evaluation system will appear "* * * stack smashing detected: * * * & lt; Unknown> Terminated "

CodePudding user response:

The building Lord solved excuse me? I also appeared the same problem, although the final run results as well as the correct answer from the (checked with the diff), but before operation is there will be a stack smashing detected warnings

CodePudding user response:

Stu Stu [n].
Instead of
Stu * Stu=new Stu [n].
Give it a try

CodePudding user response:

Reference:
//asked to write a program into the student's name, birth year, month, day. 
//the last input the name of a student output of TA was born in the year which day

# include & lt; Stdio. H>
# include & lt; Stdlib. H>
# include & lt; String. H>

Typedef struct student {
Char name [30].
Int year;
Int the month;
Int the date;
} Stu.

During the int Isleap (int) {//judgment leap year
If (year %==0 100 & amp; & Year % 400!=0)
return 0;
If (year % 4==0 & amp; & Year % 100!=0)
return 1;
If (year % 4!=0) return 0;
If (year %==0 400) return 1;
}
During the int howmanyDay (int, int the month, int the date) {//calculation and
Int sum=0;
The switch (month) {
Case 1: the sum=date; break;
Case 2: sum=31 + date; break;
Case 3: the sum=59 + Isleap (year) + date; break;
Case 4: sum=90 + Isleap (year) + date; break;
Case 5: sum=120 + Isleap (year) + date; break;
Case 6: sum=151 + Isleap (year) + date; break;
Case 7: sum=181 + Isleap (year) + date; break;
Case 8: sum=212 + Isleap (year) + date; break;
Case 9: sum=243 + Isleap (year) + date; break;
Case 10: sum=273 + Isleap (year) + date; break;
Case 11: sum=304 + Isleap (year) + date; break;
Case 12: sum=334 + Isleap (year) + date; break;
}
Return the sum.
}
Int main ()
{
int n;
The scanf (" % d ", & amp; N);//a total of how many sets of data
//Stu Stu [n].//array defined problem
Stu * Stu=new Stu [n].
Memset (stu, 0, sizeof (stu) * n);
int i;
for(i=0; iThe scanf (" % s % d % d % d ", stu [I]. Name, & amp; Stu [I]. Year, & amp; Stu [I]. The month, & amp; Stu [I] date);//data entry
}
Char c [10];
The scanf (" % s ", c);
for(i=0; iIf (STRCMP (c, stu [I] name)==0) {
Int sum=howmanyDay (stu [I] year, stu [I] month, stu [I] date);
Printf (" % d ", sum);
}
}
The delete [] stu.

return 0;
}
  • Related