The program works fine, as long as i declare the chars in readIni as static.
The way i've understood the static keyword in this situation, is that the value is retained after you leave it's scope, hence it's some kind of global variable.
Am i wrong here?
Code:
int main( int argc, char *argv[]){
//init some vars, call some other functions...
if(readIni("Inifilename")){
exit(1);
}
}
int readIni(char *fName){
static char achBuf[100], achVName[21], desc[80], achVal[31];
FILE *fi;
int i;
if (access(fName, 4) == -1 || (fi = fopen(fName, "r")) == NULL){
perror("inifile");
return(-1);
}
while (fgets(achBuf,100,fi) != NULL){
sscanf(achBuf,"%[^:]: %[^;]; %[^\n]", achVName, achVal, desc);
if (strcmp(achVName,"PARAMETER1")==0){
chEtterbeh = achVal[0];
continue;
}
}
fclose(fi);
return(0);
}