【发布时间】:2014-04-18 18:57:52
【问题描述】:
我一直在为我的程序苦苦挣扎。我正在尝试在 function1 中设置的数组中查找水平对。我的目标是在另一个函数中更改原始数组。然后处理该数组以找到水平对。
发生的一个问题是当我运行程序时,结果为零。另一个问题是函数1中的gcc警告,警告:指针和整数的比较。另一个问题是另一个 gcc 警告(由 ** 标记)警告:从不兼容的指针类型传递 'function1' 的参数 1。
感谢任何帮助,作为一个初学者,我在这个问题上花了几个小时并试图找到解决方案,但尝试使用指针并使用 struct 和 typedef 没有工作。 :(
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void function1 (int letter1[][16]);
void function2 (int letter2[][16]);
int main ( void )
{
int letter_array [13][16];
printf("\n \t\t Hello!");
printf("\n This program will create a random selection of 180 upper-case"
" characters. \n");
**function1(&letter_array);**
function2(letter_array);
return ( 0 ) ;
}
void function1 (int letter1 [][16])
{
int i, z;
srandom((unsigned)time(NULL));
for(i=0; i<=11; i++)
{
for(z=0; z<=14; z++)
{
letter1 [i][z] = random( )%26+65;
printf("%c ", letter1 [i][z]);
}
printf("\n");
}
return ;
}
void function2 (int letter2 [][16])
{
int a,b;
int m=0;
for( a = 0; a <= 11; a++)
{
for( b = 0 ; b <= 14; b++)
{
if (letter2 == (letter2 + 1))
m++;
}
}
printf("\nThe number of horizontal pairs of characters"
" are: %d", m);
return ;
【问题讨论】:
标签: c arrays multidimensional-array function-pointers