R
rudra
Hello friends, i am not a c-programmer. I generally do things using
fortran. but I need it to retrive the machine info. I write two code:
/***********************************************
uname
***********************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int operating_system(char *sys){
FILE *stream;
char *sysptr;
int bit;
sysptr = &sys[0];
sys[0] = 0x0;
stream=popen("/bin/uname -snm","r");
fread(sysptr,1,32,stream);
pclose(stream);
//printf("bit=%s\n",sysptr);
return bit;
}
and
/***********************************************
nisdomainname
***********************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int operating_sys(char *nis ){
FILE *stream;
char *sysptr;
int bit;
sysptr = &nis[0];
nis[6] = 0x0;
stream=popen("/bin/nisdomainname","r");
fread(sysptr,1,15,stream);
pclose(stream);
//printf("bit=%s\n",sysptr);
return bit;
}
which is called by fortran (f03-C interoperability). But when i am
trying to merge the code, as
/***********************************************
This code returns the machine bit
to the program bitinit
***********************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int operating_system(char *sys){
FILE *stream,*stream2;
char *sysptr,*nisptr, *nis;
int bit;
sysptr = &sys[0];
sys[6] = 0x0;
nisptr = &nis[0];
nis[0] = 0x0;
stream=popen("/bin/uname -m","r");
stream2=popen("/bin/nisdomainname","r");
fread(sysptr,1,4,stream);
pclose(stream);
printf("bit=%s\n",sysptr);
return bit;
}
and trying to run, i am getting error:
Program received signal SIGSEGV, Segmentation fault.
0x08049e72 in operating_system (sys=0x80b1d6c " ") at machine.c:15
warning: Source file is more recent than executable.
15 nis[0] = 0x0;
which i am not getting why. can you people show me where i am going
wrong?i know it is a silly mistake, but being a beginner, i request
your little time.
thanks
fortran. but I need it to retrive the machine info. I write two code:
/***********************************************
uname
***********************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int operating_system(char *sys){
FILE *stream;
char *sysptr;
int bit;
sysptr = &sys[0];
sys[0] = 0x0;
stream=popen("/bin/uname -snm","r");
fread(sysptr,1,32,stream);
pclose(stream);
//printf("bit=%s\n",sysptr);
return bit;
}
and
/***********************************************
nisdomainname
***********************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int operating_sys(char *nis ){
FILE *stream;
char *sysptr;
int bit;
sysptr = &nis[0];
nis[6] = 0x0;
stream=popen("/bin/nisdomainname","r");
fread(sysptr,1,15,stream);
pclose(stream);
//printf("bit=%s\n",sysptr);
return bit;
}
which is called by fortran (f03-C interoperability). But when i am
trying to merge the code, as
/***********************************************
This code returns the machine bit
to the program bitinit
***********************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int operating_system(char *sys){
FILE *stream,*stream2;
char *sysptr,*nisptr, *nis;
int bit;
sysptr = &sys[0];
sys[6] = 0x0;
nisptr = &nis[0];
nis[0] = 0x0;
stream=popen("/bin/uname -m","r");
stream2=popen("/bin/nisdomainname","r");
fread(sysptr,1,4,stream);
pclose(stream);
printf("bit=%s\n",sysptr);
return bit;
}
and trying to run, i am getting error:
Program received signal SIGSEGV, Segmentation fault.
0x08049e72 in operating_system (sys=0x80b1d6c " ") at machine.c:15
warning: Source file is more recent than executable.
15 nis[0] = 0x0;
which i am not getting why. can you people show me where i am going
wrong?i know it is a silly mistake, but being a beginner, i request
your little time.
thanks