Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 错误:“应答”未声明(首次在此函数中使用)_C - Fatal编程技术网

C 错误:“应答”未声明(首次在此函数中使用)

C 错误:“应答”未声明(首次在此函数中使用),c,C,我需要这个代码的帮助,我不知道该怎么做 #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> int input(float nom[],float toler[],int SIGN[],char V_F[],float *Spec_Min,float *Spec_Max); float tolerances(int size, float n

我需要这个代码的帮助,我不知道该怎么做

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


int input(float nom[],float toler[],int SIGN[],char V_F[],float *Spec_Min,float *Spec_Max);

float tolerances(int size, float nom[],float toler[],int SIGN[],char V_F[],float Spec_Min,float Spec_Max);

void adjust(int size, float nom[],float toler[],int SIGN[],char V_F[],float Spec_Min,float Spec_Max, int answer, float *dimension, float *impact, float *DgapMean, float *gaptol, float *newtol, float *newdim);


int main(void)
{
    float nom[70], toler[70], Spec_Min=0, Spec_Max=0;
    int SIGN[70];
    char V_F[70];
    int i, n;
    n = input( nom, toler, SIGN, V_F, &Spec_Min, &Spec_Max);
    for(i=0; i<n; ++i)
    {
        printf("Part: %f, %d, %f, %c\n\n", nom[i], SIGN[i], toler[i], V_F[i]);//printing off all parts and the dimensions tolerances and if the part is fixed or variable
    }
    printf("_______________________\n");
    printf("Gap: %f, %f\n\n", Spec_Min, Spec_Max);//print the size of the gap
    int size = 0;
    size = input( nom, toler, SIGN, V_F, &Spec_Min, &Spec_Max);

    tolerances(size, nom, toler, SIGN, V_F, Spec_Min, Spec_Max);
>line 43 is below this

    adjust( size, nom, toler, SIGN, V_F, Spec_Min, Spec_Max, answer, &dimension, &impact, &DgapMean, &gaptol, &newtol, &newdim);
    return 0;


}

int input(float nom[],float toler[],int SIGN[],char V_F[],float *Spec_Min,float *Spec_Max)
{
    int status, i;
    FILE *FTIN;
    FTIN = fopen ("C:\\EGR107\\input.txt", "r");

    if (FTIN == NULL)
    {
        printf("ERROR\n");//if the file didnt work show an error
        return -1;
    }
    else
    {
        for(i=0;;)
        {
            if((status = fscanf(FTIN," PART,%f,%d,%f,%c", &nom[i], &SIGN[i], &toler[i], &V_F[i]))==4)//scans parts until it doesnt start with part
            {
                ++i;
            }
            else if((status = fscanf(FTIN, " GAP,%f,%f", Spec_Min, Spec_Max))==0)//scans gap after part was scaned
            {
                fgetc(FTIN);
            }
            else if(status == EOF)
            {
                break;
            }
        }
    }
    fclose(FTIN);
    return i;
}


float tolerances(int size, float nom[],float toler[],int SIGN[],char V_F[],float Spec_Min,float Spec_Max)
    {

    int x;
    float Act_Gap, Act_Toler, Max_Gap = 0.0, Min_Gap = 0.0;
    for ( x=0, Act_Gap = 0; x<size; x++)    //does math for the tolerance
    {
        Act_Gap = Act_Gap + (nom[x]*SIGN[x]);
    }
    for ( x=0, Act_Toler = 0; x<size; x++)
    {
        Act_Toler = Act_Toler + (toler[x]);
    }
    for (x= 0, Max_Gap = 0; x<size; x++)
    {
        Max_Gap = (nom[x]*SIGN[x]+toler[x])+Max_Gap;
        Min_Gap = (nom[x]*SIGN[x]-toler[x])+Min_Gap;
    }
    printf("_______________________\n");
    printf("Actual Gap Mean: %.3f\"\n\n", Act_Gap);  //printing actual gap and gap tolerances
    printf("Actual Gap Tolerance: %.3f\"\n\n", Act_Toler);
    if (Max_Gap > Spec_Max)
    {
        printf("The Maximum gap %.3f\" is Greater than specified %.3f\"\n\n", Max_Gap, Spec_Max);//printing whether or not the max gap is greater than or less than the specified
    }
    if (Max_Gap < Spec_Max)
    {
        printf("The Maximum gap %.3f\" is Less than specified %.3f\"\n\n", Max_Gap, Spec_Max);
    }
    if (Min_Gap > Spec_Min)
    {
        printf("The Minimum gap %.3f\" is Greater than specified %.3f\"\n\n", Min_Gap, Spec_Min);//printing whether or not the min gap is greater than or less than the specified
    }
    if (Min_Gap < Spec_Min)
    {
        printf("The Minimum gap %.3f\" is Less than specified %.3f\"\n\n", Min_Gap, Spec_Min);
    }
    return 0;
}

void adjust(int size, float nom[],float toler[],int SIGN[],char V_F[],float Spec_Min,float Spec_Max,int answer, float *dimension, float *impact, float *DgapMean, float *gaptol, float *newtol, float *newdim)
{

    int i, x, status, change;
    double gapmean, Atolerance, changeinNOM, changeinTOL;

    double Part, TOL;

    for(i=0; i<size; i++)
    {
        gapmean = gapmean+(dimension[i]*impact[i]);         //gets actual gap of parts
        printf("Gap Mean: %.3f\n", gapmean);
        Atolerance = Atolerance + toler[i];             //gets actual tolerance of parts
        printf("Actual Tolerance: %.3f\n",Atolerance);

    }

    changeinNOM = *DgapMean - gapmean;                  //finds change in the dimension
    printf("Change in nominal value: %.3f\n",changeinNOM);
    changeinTOL = Atolerance - *gaptol;                 //finds change in the tolerance
    printf("Change in tolerance value: %.3f\n",changeinTOL);

    printf("____________________________\n");   //return
    printf("\n");   //return

    for(i=0; i<size; i++)
    {
        if(V_F[i] == 'V')      //looks for variable part
        {
            Part = dimension[i] - changeinNOM;          //calculates new dimension of part
            TOL = toler[i] - changeinTOL;           //calculates new tolerance of part
            if(TOL < 0)
            {
                printf("Part %d cannot be changed\n", i+1);
            }
            if(TOL >= 0)
            {
                printf("Part %d will be changed to %.3f\n",i+1,Part);
                printf("Tolerance of Part %d will be changed to %.3f\n",i+1, TOL);
                printf("Would you like to save the changes?\n");
                printf("Please enter a number value 1 for yes or 0 or no.\n");
                do
                {
                    status = scanf("%d", &answer);
                    if(x != 1 && x != 0)
                    {
                        printf("Please enter a number value 1 or 0.\n");
                        fflush(stdin);
                    }
                    if(answer == 1)
                    {
                        change = 1;
                    }
                    else if(answer == 0)
                    {
                        change = 0;
                    }
                }
                while(answer != 1 && answer != 0 || status == 0);

                if(change == 1)
                {
                    newdim[i] = Part;
                    newtol[i] = TOL;
                    printf("New Part dimension: %.3f and new part tolerance: %.3f\n", newdim[i], newtol[i] );
                    printf("Your changes have been made.\n");
                }
                else if(change == 0)
                {
                    printf("Your changes will not be saved.\n");
                }

            }

        }
    }
}

在中使用的函数的开头声明变量。在那之后留下一排空的。在使用它们的值之前,也不要忘记在某个地方初始化它们,否则您只能得到垃圾

关于警告:

必须注意使用运算符的优先级。此外,&&和| |都是二进制运算符,因此它们都有两个参数。这就是为什么你必须加括号。可能像:

while(answer != 1 && (answer != 0 || status == 0))

那么声明这些变量呢?代码中有明显的语法错误。您似乎在使用函数参数作为局部变量。只需将answer声明为局部变量,并将其从参数列表中删除。
while(answer != 1 && (answer != 0 || status == 0))