该功能第二次运行错误,即使它不是静态的

时间:2016-03-16 17:57:52

标签: c missing-data

我已经建造了一座建筑物的功能,现在在第二座建筑物上建造了两座建筑物,它因某些原因而跳过一些参数...为什么? 现在我检查了几次代码并且我没有使用任何静态varbs所以它不应该这样做...而不是为什么它会在第二次运行时记得?

UPDATE 我按照说法做了,但现在它只返回false ...任何帮助都会有帮助

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//defines
#define SIZE 30
#define Q_SIZE 4
#define TRUE 1
#define FALSE 0
struct shape
    {
    char name[SIZE];   /* name of the shape */
    int edgeNum;       /* number of edges */
    char sPol[Q_SIZE]; /* if the shape is a regular polygrom */
    };
int shapeMaker();
int main(void)
{
    int check;
    check = shapeMaker();
    if (check == TRUE)
{
    printf("the two shapes are equals!\n");
}
    else if (check == FALSE)
{
    printf("the two shapes are not equals!\n");
}
system("PAUSE");
return 0;
}

int shapeMaker()
{
struct shape firstShape;    
struct shape secondShape;

printf("please enter the first shape name: ");
fgets(secondShape.name, SIZE, stdin);
secondShape.name[strcspn(secondShape.name, "\n")] = 0;
printf("\nnow please enter the number of Edges: ");
scanf("%d", &secondShape.edgeNum);
printf("\nis the shape is regular polygom (yes/no)? ");
scanf("%s", secondShape.sPol);
getchar();
printf("\nplease enter the second  shape name: ");
fgets(secondShape.name, SIZE, stdin);
secondShape.name[strcspn(secondShape.name, "\n")] = 0;
printf("\nnow please enter the number of Edges: ");
scanf("%d", &secondShape.edgeNum);
printf("\nis the shape is regular polygom (yes/no)? ");
scanf("%s", secondShape.sPol);
if (firstShape.name == secondShape.name && firstShape.edgeNum ==      secondShape.edgeNum && firstShape.sPol == secondShape.sPol)
{
    return TRUE;
}
else
{
    return FALSE;
}
} 

1 个答案:

答案 0 :(得分:0)

在shapeMaker的开头和fgets

之后添加fflush(stdin);