SunQuest
           C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old April 6th, 2003, 06:12 AM
balance balance is offline
.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 296 balance User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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 06:18 AM.

Reply With Quote
  #2  
Old April 6th, 2003, 08:03 AM
balance balance is offline
.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 296 balance User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > not returning full value. only 1.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway