#1
  1. No Profile Picture
    .
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    296
    Rep Power
    13

    not returning full value. only 1.


    dear oh dear. this is a very simple one i think but i can't see why this is happening. i should probably have just waited until i stopped being silly but i'm going to ask anyway:

    the last part of a function that's been called from main:
    Code:
    		if(!x) {
    			printf("si: %d\n", si);
    			return si;
    		}
    	}
    	return -1;
    }
    and this is a bit of main:
    Code:
    	while (getline(line, MAXLINE) > 0)
    		if (f = strrindex(line, pattern) >= 0)
    			printf("%d\n", f);
    doesn't matter what si holds (so long as it's not 0), f comes out to be 1. so if si holds say 30, f in main is 1. in main, why isn't f 30?

    and this is the start of the function that's returning:
    Code:
    int strrindex(char *s, char *t)
    {
        ...
    Last edited by balance; April 6th, 2003 at 07:18 AM.
  2. #2
  3. No Profile Picture
    .
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    296
    Rep Power
    13
    forget this.

    it's the >= result that gets put in f, not the function result. should be with extra brackets:

    if ((f = strrindex(line, pattern)) >= 0)

    silly me.

IMN logo majestic logo threadwatch logo seochat tools logo