在C中创建int数组的数组? [英] Creating an array of int arrays in C?

查看:155
本文介绍了在C中创建int数组的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有以下方法原型:

Let us say I have the following method prototype:

void mix_audio(int *vocal_data_array, int *instrumental_data_array, int *mixed_audio_array, FOURTH ARGUMENT)
{


}

我将如何:

  1. 在上述参数之前初始化array_of_arrays以便将其作为第四个参数传递?

  1. Initialize an array_of_arrays before the above argument so as to pass it as the fourth argument?

在方法中,使它的array_of_arrays的第一个值为vocal_data数组,第二个数组为instrumental_data_array,第三个值为mixed_audio_array.

In the method, make it so that the first value of my array_of_arrays is the array called vocal_data, that the second value of my array is instrumental_data_array and the third value is mixed_audio_array.

然后我将如何遍历array_of_arrays中第一个数组的所有值.

How would I later then loop through all the values of the first array within the array_of_arrays.

我希望在这里不要问太多.我只是以为有人可以很快吐出这是一种简单的语法:)

I hope I'm not asking too much here. I just thought it would be simple syntax that someone could spit out pretty quickly :)

谢谢!

编辑1

请注意,尽管通过示例显示了长度为3的array_of_arrays,但实际上我正在寻找创建可能包含可变长度数组的东西.

Please note that although I've showed by my example an array_of_arrays of length 3 I'm actually looking to create something that could contain a variable length of arrays.

推荐答案

简单的数组数组和一个显示如何传递它的函数.我只是在数组中添加了假值,以表明已将某些内容传递给该函数,并且可以将其打印出来.数组的大小3是任意的,可以更改为所需的任何大小.每个阵列可以具有不同的大小(称为锯齿状阵列).它显示了您的三个条件:

Simple array of arrays and a function showing how to pass it. I just added fake values to the arrays to show that something was passed to the function and that I could print it back out. The size of the array, 3, is just arbitrary and can be changed to whatever sizing you want. Each array can be of a different size (known as a jagged array). It shows your three criteria:

初始化,为arrayOfArrays的每个索引分配值,该函数演示如何从数组数组中提取数据

Initialization, Assigning values to each index of arrayOfArrays, The function demonstrates how to extract the data from the array of arrays

#include <stdio.h>

void mix_audio(int *arr[3]);

int main() {
  int *arrayOfArrays[3];

  int vocal[3] = {1,2,3};
  int instrumental[3] = {4,5,6};
  int mixed_audio[3] = {7,8,9};

  arrayOfArrays[0] = vocal;
  arrayOfArrays[1] = instrumental;
  arrayOfArrays[2] = mixed_audio;

  mix_audio(arrayOfArrays);

  return(0);
}

void mix_audio(int *arr[3]) {
  int i;
  int *vocal = arr[0];
  int *instrumental = arr[1];
  int *mixed_audio = arr[2];

  for (i=0; i<3; i++) {
    printf("vocal        = %d\n", vocal[i]);
  }
  for (i=0; i<3; i++) {
    printf("instrumental = %d\n", instrumental[i]);
  }
  for (i=0; i<3; i++) {
    printf("mixed_audio  = %d\n", mixed_audio[i]);
  }
}

这篇关于在C中创建int数组的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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