I had written a program which is shown below the problem is that when I use gets() function then while executing the code in code blocks 16.01 when the gets function is called then suddenly the the code blocks stopped working. Can anyone help me out of this problem.
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <math.h>
#define PI 3.1415926535897932384626433832795
struct elements
{
float A, L, x1, y1, x2, y2;
double deg, c, s, E, esm[4][4];
int n1, n2;
} * ele;
int nonod, noele;
void elestiffmat(int);
void main()
{
int i;
char ch;
printf("\nEnter the number of nodes you want to create:");
scanf("%d", &nonod);
printf("\nEnter the number of elements you want to create:");
scanf("%d", &noele);
if (noele < (nonod - 1))
{
printf("\nThe problem is wrongly modeled.\nPress any key to abort.");
getch();
exit(0);
}
ele = (struct elements*)malloc(noele * sizeof(struct elements));
for (i = 0; i < noele; i++)
{
printf("\nCreating element %d", i + 1);
printf("\nCross sectional area?");
scanf("%f", &ele[i].A);
printf("\nYoung's Modulus?");
scanf("%Lf", &ele[i].E);
printf("\nStarting node number?");
scanf("%d", &ele[i].n1);
printf("\nIts coordinates:");
scanf("%f%f", &ele[i].x1, &ele[i].y1);
printf("\nEnding node number?");
scanf("%d", &ele[i].n2);
printf("\nIts coordinates:");
scanf("%f%f", &ele[i].x2, &ele[i].y2);
ele[i].L = sqrt(pow((ele[i].x2 - ele[i].x1), 2) + pow((ele[i].y2 - ele[i].y1), 2));
if ((ele[i].x2) - (ele[i].x1) == 0)
{
if (ele[i].y2 > ele[i].y1)
{
ele[i].deg = PI / 2.0;
}
if (ele[i].y2 < ele[i].y1)
{
ele[i].deg = (3.0 * PI) / 2.0;
}
}
if ((ele[i].y2) - (ele[i].y1) == 0)
{
if (ele[i].x2 > ele[i].x1)
{
ele[i].deg = 0.0;
}
if (ele[i].x2 < ele[i].x1)
{
ele[i].deg = PI;
}
}
if (((ele[i].y2) - (ele[i].y1)) / ((ele[i].x2) - (ele[i].x1)) < 0)
{
ele[i].deg = PI + atanf(((ele[i].y2) - (ele[i].y1)) / ((ele[i].x2) - (ele[i].x1)));
}
if (((ele[i].y2) - (ele[i].y1)) / ((ele[i].x2) - (ele[i].x1)) > 0)
{
ele[i].deg = atanf(((ele[i].y2) - (ele[i].y1)) / ((ele[i].x2) - (ele[i].x1)));
}
// printf("%g",ele[i].deg);
ele[i].c = cos(ele[i].deg);
ele[i].s = sin(ele[i].deg);
// printf("c=%g\ts=%g",ele[i].c,ele[i].s);
elestiffmat(i);
}
getch();
}
void elestiffmat(int i)
{
char choice;
ele[i].esm[0][0] = ele[i].c * ele[i].c * ele[i].A * ele[i].E / ele[i].L;
ele[i].esm[0][1] = ele[i].s * ele[i].c * ele[i].A * ele[i].E / ele[i].L;
ele[i].esm[0][2] = -ele[i].c * ele[i].c * ele[i].A * ele[i].E / ele[i].L;
ele[i].esm[0][3] = -ele[i].s * ele[i].c * ele[i].A * ele[i].E / ele[i].L;
ele[i].esm[1][0] = ele[i].s * ele[i].c * ele[i].A * ele[i].E / ele[i].L;
ele[i].esm[1][1] = ele[i].s * ele[i].s * ele[i].A * ele[i].E / ele[i].L;
ele[i].esm[1][2] = -ele[i].s * ele[i].c * ele[i].A * ele[i].E / ele[i].L;
ele[i].esm[1][3] = -ele[i].s * ele[i].s * ele[i].A * ele[i].E / ele[i].L;
ele[i].esm[2][0] = -ele[i].c * ele[i].c * ele[i].A * ele[i].E / ele[i].L;
ele[i].esm[2][1] = -ele[i].s * ele[i].c * ele[i].A * ele[i].E / ele[i].L;
ele[i].esm[2][2] = ele[i].c * ele[i].c * ele[i].A * ele[i].E / ele[i].L;
ele[i].esm[2][3] = ele[i].s * ele[i].c * ele[i].A * ele[i].E / ele[i].L;
ele[i].esm[3][0] = -ele[i].s * ele[i].c * ele[i].A * ele[i].E / ele[i].L;
ele[i].esm[3][1] = -ele[i].s * ele[i].s * ele[i].A * ele[i].E / ele[i].L;
ele[i].esm[3][2] = ele[i].s * ele[i].c * ele[i].A * ele[i].E / ele[i].L;
ele[i].esm[3][3] = ele[i].s * ele[i].s * ele[i].A * ele[i].E / ele[i].L;
printf("\nDo you want to print the element stiffness matrix (y/n)?");
gets(choice);
if (choice == 'y' || choice == 'Y')
{
printf("\nThe element stiffness matrix of the element %d is:-", i + 1);
int j, k;
for (j = 0; j < 4; j++)
{
printf("\n");
for (k = 0; k < 4; k++)
{
printf("%15g", ele[i].esm[j][k]);
}
}
}
}