c - Strings overlap when fwrite is called from function -


my assignment display kernel information , have output log file. program long because contains alot of parts display necessary ones. main method calling part1()-part10() functions. output is:

1. cpu tintel(r) 

when expected:

1. cpu type & model:     intel(r) core(tm) i5-4210u cpu @ 1.70ghz 

part1():

int part1() {     char filename[] = "/proc/cpuinfo";     file *fp = fopen(filename, "r");     int n = 5; // line on information 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; } 

output():

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); } 


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -