evrything was fine until i inserted 100 to 125 lines in code.
i am wondering what kv is doing wrong as it is not even printing that version file was opened..
any sort of help is appreciated.
files included in the code are given below for reference.
proc/version file:
**
Linux version 2.6.38-15-generic (buildd@panlong) (gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4) ) #65-Ubuntu SMP Thu Jul 26 20:16:13 UTC 2012**
#include <stdio.h>
#include <string.h>
#include <assert.h>
int main()
{
char *a="9";
char *b="0";
if(strcmp(a,b)>0)
printf("started \n");
int cpu=0,flag=0,count=0,core,siblings,physid=-1,prevphysid,bat,seal=0;
char str1[200],model[100],version[1000];
char *ss;
FILE *fp,*kv;
fp=fopen("/proc/cpuinfo","r");
if(fp)
{
while(fgets(str1,200,fp)!=NULL)
{
if(seal==0)
{
if(strstr(str1," lm "))
{
bat=64;
seal=1;
}
else
{
printf("false");
bat=32;
}
}
ss=strtok(str1,":");
if(strncmp("cpu cores",ss,9)==0)
{
ss=strtok(NULL,"\n");
sscanf(ss,"%d",&core);
}
if(strncmp("siblings",ss,8)==0)
{
ss=strtok(NULL,"\n");
sscanf(ss,"%d",&siblings);
}
if(strncmp("model name",ss,10)==0)
{
ss=strtok(NULL,"\n");
sscanf(ss,"%[^\n]",model);
}
if(strncmp("physical id",ss,11)==0)
{
if(physid!=-1)
prevphysid=physid;
ss=strtok(NULL," ");
sscanf(ss,"%d",&physid);
if(cpu==0)
cpu++;
else if(physid>prevphysid)
cpu++;
}
}
printf("exited \n");
//printf("core=%s \n",cores);
printf("cores is %d \n",core);
printf("siblings is %d \n",siblings);
printf("model is %s \n",model);
if(siblings>core)
printf("hyperthreading enabled ");
printf("%d cpu \n",cpu);
assert(bat=64);
printf("bat is %d",bat);
if(cpu>1)
printf("%d cpu \t",cpu);
assert(bat=64);
}
//fclose(fp);
//printf(" \n %s \t \n",model);
kv=fopen("/proc/version","r");
printf("opened");
printf("entered");
if(fgets(str1,200,kv)!=NULL)
{
printf("entering ing first");
ss=strtok(str1," ");
while(ss!=NULL);
{
printf("entering first");
if(strncmp("version",ss,7)==0)
{
sscanf(ss,"%s",version);
printf("kernel version is %s",version);
}
ss=strtok(NULL," ");
printf("exiting first");
}
printf("exiting second");
}
//else("failed to open");
fclose(kv);
printf("kernel version is %s",version);
}