Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 从函数调用fwrite时,字符串重叠_C_Function_File_Output_Fwrite - Fatal编程技术网

C 从函数调用fwrite时,字符串重叠

C 从函数调用fwrite时,字符串重叠,c,function,file,output,fwrite,C,Function,File,Output,Fwrite,我的任务是显示内核信息,现在我必须将其输出到日志文件中。程序很长,因为它包含很多部分,所以我将显示必要的部分。主要方法只是调用part1()-part10()函数。我的输出是: 1. CPU tIntel(R) 预计会出现这种情况时: 1. CPU type & model: Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz 第1部分(): 你需要的不是“sizeof”!!!“sizeof(char*)”可能是“4”(对于32位系统)谢谢我经常

我的任务是显示内核信息,现在我必须将其输出到日志文件中。程序很长,因为它包含很多部分,所以我将显示必要的部分。主要方法只是调用part1()-part10()函数。我的输出是:

1. CPU tIntel(R)
预计会出现这种情况时:

1. CPU type & model:     Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz
第1部分():


你需要的不是“sizeof”!!!“sizeof(char*)”可能是“4”(对于32位系统)谢谢我经常被这两个弄糊涂-
int part1()
{
    char filename[] = "/proc/cpuinfo";
    FILE *fp = fopen(filename, "r");
    int n = 5; // Line on which information is contained. 
    int i;
    char line[256];

    if(fp != NULL)
    {    
        for(i=0; i<=n-1; i++)
        {
          fgets(line, sizeof(line), fp);
        }

        fclose(fp);

        printf("1. CPU type & model:\t %s", line+13);
        output("1. CPU type & model:\t", line+13);
        return 0;
    }
    else
      return 1;
}
int output(char *x, char *y)
{
  FILE *fp;

  fp = fopen("local_kernel.log ", "a");

  fwrite(x , 1 , sizeof(x) , fp );
  fwrite(y , 1 , sizeof(y) , fp );

  fclose(fp);
}