その通りです。
私は半分アメリカ人の血が混じっています。
本当は英語の方がわかり易いです。
すみません。
>>// ファイル名固定にしてみるとか「1107.wav」など
>はどうですか?
現象は同じです。
同じところでとまります。
>>新規プロジェクトを作ってみて以下は動きます?
>はどうでした?
これも、プロジェクトを新しく
作りましたが、同じ現象でした。
Try following code:
#include <stdio.h>
int main() {
FILE* fp;
char fn[16];
int HMOD;
int HnC;
for ( HMOD = 1; HMOD < 100; HMOD++ ) {
for ( HnC = 0; HnX < 20; HnC++ ) {
sprintf(fn, V%02d%02d.wav, (HMOD-1), HnC);
fp = fopen(fn, rb);
if ( !fp ) {
printf(can't open '%s'\n, fn);
return 1;
}
fclose(fp);
}
}
printf(OK!\n);
return 0;
}
If you see 'OK!', I believe your original code should have some difficulties.
Otherwise, show me the file-name you see.
>>>// ファイル名固定にしてみるとか「1107.wav」など
>>はどうですか?
>
>現象は同じです。
>同じところでとまります。
>
「V1007.wav」のファイルが壊れているということはないでしょうか?
NT系OSならセキュリティで引っかかっているとか・・・
You can't ignore any advises/questions posted here, no matter what language they
are written in. Who could ever solve a problem just making a new question and
leaving given advises alone?
You can get somewhere else to ask it if you prefer English rather than Japanese.
>「V1007.wav」のファイルが壊れているということはないでしょうか?
> NT系OSならセキュリティで引っかかっているとか・・・
いいえ。
V1007.wavは他のV1005.wavやV1006.wav
と同じよに、壊れていません。
WINDOWS95でも98でも2000でも現象は同じです。
Thanks for your writing English!
No.
I've already checked that its file V1007.wav is normal,
because if I should open this FILE at the first loop,
No problem.
>If you see 'OK!',
>I believe your original code should have some difficulties.
>Otherwise, show me the file-name you see.
I embedded your short code and ran it,
just the part of
for ( HnC = 0; HnX < 20; HnC++ ) {
is mistaken as
for ( HnC = 0; HnC < 20; HnC++ ) {
though.
(It's up to me.)
Unluckily I saw OK!.
> You can get somewhere else to ask it
> if you prefer English rather than Japanese.
Thanks a lot.
I'll think about this contradiction
looking at the change for circumstances.
> Unluckily I saw OK!.
hmmm... so we were NOT able to find bugs.
as you have not shown us other stuff of your code.
# do you keep big amount of memories for each file-processing?
# do you forget closing file after reading at some special condition?
# do you keep big amount of memories for each file-processing?
Yes.
I should have used malloc/calloc and free.
# do you forget closing file after reading at some special condition?
No. I've already counted number of fopen and close each.
はぁ~、眠れない…。慣れない日本語に苦労しながらもわざわざここの掲示板を
頼って相談してくれているのに、とても気の毒で気になっちゃって…。(;_;)
ここまで来たら何とか解決してあげたい! …ということで、英語が得意な方!
必要なら是非翻訳をお願いします。とりあえずここのスレッドのやりとりから汲み
取れる問題点と自分なりの考察をまとめてみました。
■問題点
1、for文による2重ループ処理の中でファイルのオープンクローズを繰り返して
いるが、特定のファイルでオープンに失敗する。
2、問題の発生するループ回数は明らかになっていて、少なくとも外側のループが
10回目、内側のループが7回目の時であると思われる。
3、問題のループ処理を単純化すると以下の形になる。
for (int i = 1; i < 100; i++ )
for (int j = 0; HnX<20; j++)
4、オープンするファイル名はループの中で生成される。ロジックは以下の通り、
上記のfor文にあわせて変数名を一部単純化
sprintf(fn, V%02d%02d.wav, (i-1), j);
5、ファイルのオープンロジックは以下の通り、ファイル名fnのバッファサイズは
10なので、実質9文字(+終端1文字)しか格納できない。
char fn[10];
if ((fp = fopen(fn, rb)) == NULL)
6、本人曰く、fopenとfclose関数の対応はとれている。
■考察
・上記ループの中で内側のループ条件は、「HnXという変数が20未満の時」だが、
HnXについてはまったく不明、少なくとも内側のループは『20回で終わるとは
限らない』ことがわかる。
・ファイル名を格納するバッファサイズが小さいため、内側のループが二桁を超
えると用意されたバッファを突き抜けてしまうことがわかる。
・fopen関数の失敗時にファイルポインタfnにNULLが設定されているということか
ら、可能性として以下のことが考えられる。
1)オープンしようとするファイル名が誤っている。
2)オープンしようとするファイルが然るべき場所に存在しない。
3)オープンしようとするファイルが他のプロセス等で排他的に開かれていて
開けない
4)オープンしようとするファイルが壊れている。
このスレッドから私が読みとれるのはこの辺が限界です。どなたかもっと細かい
フォローを入れられませんか? 何とか解決してあげたいです。
問題解決したわけではありませんが、
「ふじ」さんが少しでも理解していただけるよう、私なりに
「ひょっとして」さんの発言にある、問題点と「ひょっとして」さんの
考察を翻訳してみました。
少しでも「ふじ」さんの理解につながればいいなぁと思います。
上記の翻訳-The above-mentioned translation-
Although problem solution was not necessarily carried out, consideration of
the problem in his(hyottosite) remark and his was translated into me so that
you might understand. I think that what is necessary is just to lead to your
understanding.
■Problem
1.Open closing of a file is repeated in the double
loop processing by the for sentence.
Although it is, a specific file goes wrong openly.
2.The number of times of a loop which a problem generates is clear,
and an outside loop is considered at least for the loop of the 10th inner side
to be a time of being the 7th time.
3.It will become the following forms if the loop processing in question is
simplified.
for (int i = 1; i < 100; i++ )
for (int j = 0; HnX<20; j++)
4.The file name to open is generated in a loop.
sprintf(fn, V%02d%02d.wav, (i-1), j);
5.Logic has simplified a part of variable name in accordance with the above-
mentioned for sentence as follows.
char fn[10];
if ((fp = fopen(fn, rb)) == NULL)
6.The open logic of a file is as follows the buffer size of a file name fn.
Since it is 10, only the substance of nine characters (+ terminus of one
character) is unstorable.
7.Correspondence of a he reason, and fopen and fclose function can be taken.
■Consideration
・Although inside loop conditions are the times of a variable called HnX
being less than 20 in the above-mentioned loop,
about HnX, it is completely unknown and what an inside loop at least does not
necessarily finish as 20 times is understood.
・Since the buffer size which stores a file name is small,
it turns out that it runs through the buffer prepared when the inside loop
exceeded 2 figures.
・Since it says that NULL is set as the file pointer fn at the time of failure
of a fopen function,
the following things can be considered as the possibility.
1.The file name which it is going to open is mistaken.
2.The file which it is going to open does not exist
in an appropriate place.
3.In other processes etc., the file which it is going to open is
opened exclusively and does not open.
4.The file which it is going to open has broken.
しん様、ありがとうございます。ここまで完全に翻訳していただけるなんて、
猛烈に感激しております。ふじさんの問題解決につながることを心から祈ってお
ります。
> 慣れない日本語に苦労しながらもわざわざここの掲示板を頼って相談してくれているのに
なるほど、おっしゃる通りだと思います。
で、2つに分かれていて英語も入り混じっているので、よく読み取れないのですが(すみませ
ん)
> 1. V1007.wav だけをオープンしてみる。OKか?
は実行されているのでしょうか?
OKだった場合、エラーが出るファイル名は、本当にV1007.wavなのかを確認してはどうでしょ
うか?
初歩的な事ですが、思い込みで実は違っていたなんて事が自分の場合よくあるので。
それに、これ以上の事は思いつかないもので。
> 1.V1007.wav is opened. Is O.K. or ? performed?
How about checking whether when it is O.K., the file name out of which an
error comes is V1007.wav truly? Although it is elementary, since it is with
the sufficient case where things are it themselveses that convinced and came
out and it was different in fact.
The thing beyond this does not happen not to think to it.
The above is the text created to the translation site.
私は英語は全く出来ませんので、翻訳サイトで作成した文章です↑
こりゃおかしいぞ、という方は(改行も変ですし)添削して下さいませ。
> επιστημη 2003/05/12(月) 23:22:36
このコードを試して 'OK!' だったとの報告が
ありますから、
原因は僕らの'知らないところ'にあるはずです。
# メモリーその他のリソースを食い潰してるん
# じゃないかなー...て雰囲気ですが。
> このコードを試して 'OK!' だったとの報告が
> ありますから、
> 原因は僕らの'知らないところ'にあるはずです。
あ、その後のFujiさんの書込みはそういうことだったんですね(^^;)
失礼いたしましたぁ。
1)for文のHMODの開始を2にするとどうなりますか?
for (HMOD=2;HMOD<100;HMOD++)
2)HMODのfor文とHnCのfor文を入れ替えるとどうなりますか?
for (HnC=0;HnC<20;HnC++)
for (HMOD=1;HMOD<100;HMOD++)
上記の場合でも、HMOD=11,HnC=7の時にエラーになりますか?
別の値の時にエラーになるならば、ファイルが原因ではないと思います。
fopenとfcloseの数があっていても、正常に動作しているとは限りません。
fcloseでエラーになっていないか、リターン値を確認してみてください。
...'ファイルの異常'ってセンは消えてるんじゃないのかなぁ...