I have a problem with my code, good news is I actually pinpointed the problem, bad news is I do not understand why it is a problem. Also should this be return or exit? This is my getNums() function,…so far. first my code calls getLine() which gets the line and returns its character length. Then get nums is given, the line, length of the line, and an empty array to put numbers in. and is suppose to return the number of numbers it just put in.
int getNums(char s[], int endMarker, int numarray[])
{
char c;
double value;
int counter =0;
int i,j;
for(i=0;i<endMarker;i++) {
while ((c=s[i]!='\n')&&(c!=' ')) {
//errors
if ( (c<'0') || (c>'9') ) {
return(-1); //was exit testing return, **this always kicks me out**
if( counter > 6){
return(-2);
} //was exit testing return
s[i]=c;
i++;
value = value*10+'c'-'0';
}else
numarray[j]=value;
j++;
counter++;
}
if ((c=getchar())==' ') {
i++;
}
}
return (counter);
printf("%c,%c:",counter,value); // for testing
}
c=s[i]!='\n'isn’t doing what you think it’s doing. The inequality operator has higher precedence than the assignment operator. The variablecwill be set to one ifs[i]isn’t equal to'\n', and will be set to zero if it is equal.You should either move the assignment to an earlier statement, or put parentheses around it.