Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.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 我们正试图存储通过readPoly函数输入的多个数组_C_Polynomials - Fatal编程技术网

C 我们正试图存储通过readPoly函数输入的多个数组

C 我们正试图存储通过readPoly函数输入的多个数组,c,polynomials,C,Polynomials,我们的Read Poly函数接受多项式中X的每个值的系数,并按升序指定它们的指数。我们希望使用此函数存储多个多项式,以便在代码的其他函数中使用 #include <stdio.h> #include <stdlib.h> //#include "functions.c" //#include "declaration.h" int maxOrder = 0; int g=0; //int numPoly[g]; typedef struct _poly { in

我们的Read Poly函数接受多项式中X的每个值的系数,并按升序指定它们的指数。我们希望使用此函数存储多个多项式,以便在代码的其他函数中使用

    #include <stdio.h>
#include <stdlib.h>
//#include "functions.c"
//#include "declaration.h"
int maxOrder = 0;
int g=0;
//int numPoly[g];

typedef struct _poly
{
int coeff;
}poly;

int readPoly(int maxOrder)
{
    int j;
    int i;
    poly p[maxOrder];

    for(i=0; i<maxOrder;i++){
    printf("\n Enter the Coefficient of x^(%d):",i);
    scanf("%d",&p[i].coeff);
    }
    printf("\n Your Polynomial:");
    for(j=0;j<(maxOrder)-1;j++){
    printf("%dx^(%d)+", p[j].coeff, j);
    }
    printf("%dx^(%d)\n", p[j].coeff);
    return(maxOrder);
    //g=p;
 }

double main()
{

    int loop = 0;

    do
    {
        printf("Hi, Welcome to polynomial-mania a program by Eoghan, Fionn, Ciaran\n") +
        ("What action would you like to take. Please enter a number");
        printf("1. Create a poly\n");
        printf("2. Delete a poly\n");
        printf("3. Add 2 polys\n");
        printf("4. Subtract 2 polys\n");
        printf("5. Multiply 2 polys\n");
        printf("6. Divide one poly by another\n");
        printf("7. Return the order of a polynomial\n");
        printf("8. Normalise a polynomial\n");
        printf("9. Print a polynomial\n");
        printf("10. Test this program\n");
#包括
#包括
//#包括“functions.c”
//#包括“declaration.h”
int maxOrder=0;
int g=0;
//int numPoly[g];
typedef结构
{
内因系数;
}聚;
int-readPoly(int-maxOrder)
{
int j;
int i;
poly-p[maxOrder];

对于(i=0;i尝试编写函数:
int-readPoly(Poly*p,int-maxOrder)
…scanf可能会失败,您在哪里控制这种情况?…或者您可能希望使用一些输入的代码来停止数据传输,为什么不?有没有更好的方法来接受多项式的值以这种方式存储它们?如果scanf不起作用?我们也必须编写一个测试用例,这样scanf可能不是最好的wat
double main()
是有问题的-如果您要处理命令行参数,它应该是
int main(void)
int main(int argc,char**argv)
。您的
main()
代码似乎非常不完整。如果您的多项式可以有许多不同的大小,那么您可能需要使用动态内存分配(
malloc()
free()
等)。如果你还没有学会这些,生活会变得更加棘手-你必须对多项式的大小设定一个上限,并检查你没有得到太多的系数。