c - 这段代码有什么问题? Eventhe printf 没有被打印出来

标签 c

这段代码有什么问题,即使 printf 不工作。但是编译成功

#include <speex/speex.h>
 #include <stdio.h>
 #include <stdlib.h>
 /*The frame size in hardcoded for this sample code but it doesn't have to be*/
 #define FRAME_SIZE 160



int main()
 {
   printf("decoding");
   char *outFile;
   FILE *fout, *fs;
   short out[FRAME_SIZE];
   float output[FRAME_SIZE];
   char cbits[200];
   int nbBytes;
   void *state;
   SpeexBits bits;
   int i, tmp;
   fout = fopen("test_40khz_mono_Q5.spx", "rb");
   if(fout == NULL){
   printf("******Error*******");
   }
   else{
   printf("*******Okay********");
   }

    fs = fopen("pcmfile","wb");
   if(fs == NULL){
   printf("****Error pcm creation****");
   }
   else{
   printf("*****pcm File created*****");
   }
state = speex_decoder_init(&speex_nb_mode);

   tmp=1;
   speex_decoder_ctl(state, SPEEX_SET_ENH, &tmp);
    speex_bits_init(&bits);

   while (!(feof(fout)))
   {
    fread(&nbBytes, sizeof(int), 1, fout);
    fread(cbits, 1, nbBytes, fout); //Problem area
     speex_bits_read_from(&bits, cbits, nbBytes);
     speex_decode(state, &bits, output);

     for (i=0;i<FRAME_SIZE;i++)
      out[i]=output[i];

       fwrite(out, sizeof(short), FRAME_SIZE, fs);
   }

    speex_decoder_destroy(state);
    speex_bits_destroy(&bits);
   fclose(fout);
   fclose(fs);
  return 0;
}

最佳答案

很可能你的 printf 正在被缓冲,你的程序可能崩溃了(你没有说发生了什么),导致缓冲区被丢弃。在 *nix 中,输出通常是行缓冲的,如果您结束该行,您将 printf 开始工作,如下所示:

printf("decoding\n");

或者您可以明确地刷新缓冲区(在某些平台上您可能需要这样做)

printf("decoding\n");
fflush(stdout);

除此之外,如果我们得不到更多信息,就很难为您提供帮助。它会崩溃吗?它会打印类似“Segmentation fault”或类似的内容吗?

HTH

关于c - 这段代码有什么问题? Eventhe printf 没有被打印出来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4816405/

相关文章:

c - 为什么这些构造使用增量前和增量后未定义的行为?

c - 将 C 代码翻译成 Haskell

创建和使用字体/避免 Windows GDI 中的内存泄漏

c - 当内核重新启动时,延迟套接字会发生什么?

c++ - 是否有一种优雅的方式来处理 Windows OpenGL 应用程序中全屏和窗口模式之间的切换?

将字符串复制到c中的剪贴板

c - 由于 gcc 特定语法,如何阻止 Eclipse CDT 发出错误?

c - C中的转换和分配int,char之间的区别

c++ - glmapbufferOES 和 glunmapbuffer 在 opengl-es 2.0 中未声明

c - 使用 C 中的文件处理程序执行 hello.c 文件