我在計算文件的大小。我遵循的過程是讀取文件並將其存儲在數組中並計算其大小。然而,我真的不知道......我嘗試了n種方法......我將這個大小作爲屬性傳遞給頻率函數,並與數組的名稱一起使用。計算陣列的大小
#include <stdio.h>
#include<conio.h>
void frequency (int theArray [ ], int ??????, int x)
{
int count = 0;
int u;
for (u = 0; u < ??????; u++)
{
if (theArray[u]==x)
{
count = count + 1 ;
/*printf("\n%d",theArray[u]);*/
}
else
{
count = count ;
}
}
printf ("\nThe frequency of %d in your array is %d ",x,count);
}
void main()
{
FILE*file = fopen("num.txt","r");
int integers[100];
int i=0;
int r = 0;
int num;
int theArray[100];
int there[100];
int n;
int g;
int x;
while(fscanf(file,"%d",&num)>0)
{
integers[i]=num;
printf("\n%d",(integers[i]));
there[r] = integers[i];
i++;
}
//printf("%d",there[r]);
//printf("\n%d",file);
//fclose(file);
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(integers,????????,x);
getch();
fclose(file);
}
??????
是從哪裏讀取文件並存儲它的整數數組的大小。
我無法找到一種方法來計算我複製我的文件的數組的大小。我的想法是計算該文件中一個數字的頻率並計算它出現的概率,從而計算出熵。建議請!
我不知道是否有任何函數來計算數組的長度,但您可以初始化所有元素爲-1,然後複製所有數據,最後檢查直到-1。而且對於良好的編碼,你需要分開跟蹤每個角色,以便它必須明確。 – Avinash 2014-09-21 05:28:57
檢查這個http://stackoverflow.com/questions/8236/how-do-you-determine-the-size-of-a-file-in-c – nem035 2014-09-21 05:31:28
調用頻率(整數,我,x);' – BLUEPIXY 2014-09-21 05:40:47