Here is the c code:-
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(int argc,char *argv[]){
if(argc==1){ //default
printf("first version\n");
int i,j,k;
char line[1024],*str1,*str,str2[1024],ch;
FILE *in=fopen("/proc/cpuinfo","r");
i=0;
while((fgets(line,1024,in))!=NULL){
// printf("%s",line);
str=strtok(line, " :");
if(str!=NULL){ //point 1
if(strcmp(str,"model")==0){
printf("%d %s\n",i,str); //point 2
str=strtok(NULL, " :");
printf("%s\n",str); //printing "name"
if(strcmp(str,"name")==0) //point 3
printf("CPU Model:=%s\n",strtok(NULL,":"));
}
else
continue;
}
i++;
}
fclose(in);
}
}
At point 1 string str is "model" but at point 2 it is not printing str and also at point 3 it is not going into if sentence.
Can anyone figure out what's the problem with this code ?
Any help should be appreciated.