On HPUX compile as ANSI C this does not segfault-
segfaulting is trying to access memory your processes does not own.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
void help(void);
int main(int argc, char *argv[])
{
int i;
int j=0;
int z=0;
int st_stevk=0;
float sklad[20]={0.};
float plus[20]={0.};
if(argc<4)
{
help();
exit(EXIT_FAILURE);
}
for(i=0;i<argc;i++)
{
if(isdigit(*argv[i]))
{
sklad[j]=atof(argv[i]);
j++;
st_stevk++;
continue;
}
if((st_stevk>=2)&&(isalpha(*argv[i])) )
{
z=j-st_stevk;
switch(*argv[i])
{ //ascii kode od operatorjev
case '+':
for(i=0;i<st_stevk;i++)
{
plus[i]=sklad[z];
z++;
}
break;
default:
break;
}
st_stevk=0;
}
}
return 0;
}
void help(void)
{
printf("\n");
printf("%s","Vpisati moras vsaj tri argumente!\nPrimer: ./sedma 3 4 +, pri tem pa\n");
printf("%s", "mora biti operator vedno za zadnjim\n");
printf("%s","operandom, ki ga operacija zajema\n");
}