无法转换为(int *)为int [英] Unable to convert (int*) to int

查看:330
本文介绍了无法转换为(int *)为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想读取具有所有号的文本文件中的元素,并将其作为参数传递给了频率()中给出below.However功能,它显示了一个错误,说
int类型的参数是与类型为(int *)的参数不兼容。我想尽一切办法转换为(int *)来诠释,但最终miserably..below贴是我的C code。

 无效的主要()
     {
    FILE *文件=的fopen(num.txt,R);
    INT整数[100];
    INT I = 0;
    INT H [100];
    INT NUM;
    INT theArray [100];
    诠释N,K;
    INT克;
   INT X,L;
    而(的fscanf(文件,%d个,试验#)大于0)
   {
      整数[i] = NUM​​;
     K =(int)的整数[I];    的printf(%d个\\ N,K);      我++;
   }
  的printf(!\\ n确定,由于现在是什么号码执行您想要搜索的频率,您的阵列?);   scanf函数(\\ N%D,&安培; X); / *存储号码进行搜索频率* /      频率(K,N,x)的;
      残培();
      FCLOSE(文件);    }
无效频率(INT theArray [],INT N,INT X)
 {
  诠释计数= 0;
 诠释U;
//的printf(%d个,N);
  对于(U = 0; U< N;ü++)
   {
    如果(theArray [U] == X)
    {
        数=计+ 1;
        / *的printf(\\ N%D,theArray [U]); * /
    / *的printf(\\ N%D,计数); * /
    }
    其他
    {
        数=计;
    }
     }     的printf(阵列在%d的\\ n此频率为%d,x,算);
  }

这样的想法是,通过num.txt读元件被存储在数组数k和相同的阵列具有在频率函数传递!然而,在我的情况下,它说:int类型的参数是与类型为(int *)的说法不符。


解决方案

 频率(K,N,X);
           |
           |
           + --- INT?

 频率(INT theArray [],诠释N,INT X)
                     |
                     |
                     +接受一个int *

您的通话功能

 频率(整数,I,X);

在你的主,只是宣布他们不会的神奇 N 和 theArray EM>通过他们在其他功能。

I'm just trying to read the elements from a text file that has all the numbers and pass it as an argument to the "frequency()" function given below.However,It shows up an error saying that "argument of type int is incompatible with argument of type (int*)" . I tried everything to convert (int*) to int but ended up miserably..below posted is my C code.

  void main()
     {
    FILE*file = fopen("num.txt","r");
    int integers[100];
    int i=0;
    int h[100];
    int num;
    int theArray[100];
    int n,k;
    int g;
   int x,l;
    while(fscanf(file,"%d",&num)>0)
   {
      integers[i]=num;
     k =(int)integers[i];

    printf("%d\n",k);

      i++;
   }


  printf ("\n OK, Thanks! Now What Number Do You Want To Search For Frequency In Your Array? ");

   scanf("\n%d", &x);/*Stores Number To Search For Frequency*/

      frequency(k,n,x);
      getch();
      fclose(file); 

    }


void  frequency (int theArray [ ], int n, int x)
 {
  int count = 0;
 int u;
//  printf("%d",n);


  for (u = 0; u < n; u++)
   {
    if ( theArray[u]==x)
    {
        count = count + 1 ;
        /*printf("\n%d",theArray[u]);*/
    /*  printf("\n%d",count);*/


    }      
    else
    {
        count = count ;
    } 
     }

     printf ("\nThe frequency of %d in your array is %d ",x,count);


  }

So the idea is that the elements read through "num.txt" are stored in an array 'k' and the same array has to be passed in the frequency function! However,in my case it is saying "argument of type int is incompatible with argument of type(int*).

解决方案

 frequency(k,      n,       x);
           |
           |
           +---int ?

But

frequency (int theArray [ ], int n, int x) 
                     |
                     |
                     + accepts an int*

Call your function as

frequency ( integers, i, x );

You never initialized n and theArray in your main, simply declaring them will not magically pass them in other functions.

这篇关于无法转换为(int *)为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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