Nov 17, 2009 at 12:14pm UTC
1 2 3 4 5 6 7 8 9 10 11 12
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
char *envstrn;
int main( int argc,char *argv[]) {
if (argc==2) {
envstrn=getenv(argv[1]);
printf("%s\n" ,envstrn);
}
return 0;
}
when the above program is rum with arguments HOME OR SHELL OR PATH , it gives results. But when OSTYPE is used i gives segmentation fault??
regards
Last edited on Nov 17, 2009 at 12:15pm UTC
Nov 17, 2009 at 1:16pm UTC
it returns a null pointer and you aren't checking.
Nov 17, 2009 at 2:01pm UTC
i also know that its returning a null pointer.. but why... when i normally give
echo $OSTYPE iget back my os??
regards
Nov 17, 2009 at 3:58pm UTC
hello seph.. so you mean that otherwise the program is fine.. actually i dint prepare for that NULL because i dint think that OSTYPE wont return a value as it was doing in the console.. Thanks for ur help.. i was great.. :-)
regards
Nov 18, 2009 at 9:09am UTC
echo itself is a program which takes care of all these things, your program should take care of these errors.