不允许不完整的类型 [英] incomplete type not allowed

查看:147
本文介绍了不允许不完整的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iam尝试使用函数引用制作一个程序来交换二维数组,在编写时我告诉我未使用的不完整类型



iam trying to do make a program to swap a 2d array using function reference and when writing it i tell me incomplete type not used

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

    void swap(int *x[][2],int x1,int y1,int x2,int y2)
    {
	int temp=*x[x1][y1];
	*x[x1][y1]=*x[x2][y2];
	*x[x2][y2]=temp;
    }

    int main (void)
    {
	int arr[2][2];
	printf("Enter the array ");
	for (int i=0;i<2;i++)
	{
		for(int j=0;j<2;j++)
		{
			scanf("%d",&arr[i][j]);
		}
	}
	for(int i=0;i<2;i++)
	{	
		for(int j=0;j<2;j++)
		{
			printf("%d",&swap(arr,0,0,0,0));
		}
	}
	getch();
    }





[edit]已添加代码块 - OriginalGriff [/ edit]



[edit]Code block added - OriginalGriff[/edit]

推荐答案

您不需要将指针传递给数组就地更改其元素。例如,以下代码将第一个与2x2数组的最后一项交换:



You don't need to pass a pointer to an array to in-place change its elements. For instance, the following code swaps the first with the last item of the 2x2 array:

#include <stdio.h>

void myswap( int a[][2], int x1, int y1, int x2, int y2)
{
  int temp = a[x1][y1];
  a[x1][y1] =  a[x2][y2];
  a[x2][y2]= temp;
}


void dump(int a[][2], int n)
{
  int i, j;
  for (i=0; i<n; ++i)
  {
    for (j=0; j<2; ++j)
      printf("%d ", a[i][j]);
    printf("\n");
  }
}


int main (void)
{
  int arr[2][2];
  int i,j;
  printf("Enter the array ");

  for (i=0;i<2;i++)
  {
    for(j=0;j<2;j++)
    {
      scanf("%d",&arr[i][j]);
    }
  }
  dump(arr, 2);
  myswap(arr, 0, 0, 1, 1);
  dump(arr, 2);
  return 0;
}


这篇关于不允许不完整的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆