gpt4 book ai didi

c - 程序传递 if 语句并需要指向对象类型的指针

转载 作者:行者123 更新时间:2023-11-30 20:26:56 25 4
gpt4 key购买 nike

我一直跳过我的代码的一部分,这是当用户选择 zero 时,我转到 if select 0 then 执行此操作,但它只是完全跳过它

if (select = 0)
{
for ( i = 0; i < 20; ++i)
printf("%d", array[i]);
//// whenever I enter zero it skips over this if entirely
}

此外,当我尝试调用函数并打印它时,我不断得知我必须有一个指向对象类型的指针

    if (select = 1)
{


square(array, 20);

for( j = 0; j < 20; ++j);
printf("%d", a[j]);
//the j reads that I need a pointer-to-object type
}

这是我的完整代码。这是一项旧作业,我正在尝试重新学习东西

    #include<stdio.h>
#include<conio.h>

void initialize(int a[], int size)
{

int i;


}

void square(int a[], int size)
{
int j;

for( j = 0; j < size; ++j)
a[j] = a[j] * a[j];



}





int main (void)
{


int array[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,19};
int i,j,k,l,m, select, a, size;


void initialize ( int a[], int size);
void square ( int a[], int size);


printf("Please select an option from the form \n\n 0 - initialize \n\n 1 - square \n\n 2 ");
scanf("%d", &select);





if (select = 0)
{
for ( i = 0; i < 20; ++i)
printf("%d", array[i]);
//// whenever I enter zero it skips over this if entirely
}
if (select = 1)
{


square(array, 20);

for( j = 0; j < 20; ++j);
printf("%d", a[j]);
//the j reads that I need a pointer-to-object type
}



}

最佳答案

= 是赋值运算符。使用 == 比较值。

在您询问的第二个错误中,a 在您的 main() 函数中被声明为整数:

    int i,j,k,l,m, select, a, size;

您可能想在该 printf 语句中使用 array 而不是 a

关于c - 程序传递 if 语句并需要指向对象类型的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23327880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com