Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
18 June, 2013, 23:09:27 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1]   Go Down
  Print  
Author Topic: Problem with C code -  (Read 649 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
lkj
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: Today at 22:21:24
Date Registered: 07 September, 2011, 20:05:25
Posts: 362

Topic starter
Total Post Ratings: +40

View Profile
« on: 07 September, 2011, 20:28:05 »
0

I have a problem with the following  code:


1
2
3
for(w = 0, w < levelheader->number_of_eggs, ++w){
        //do something
}
Where levelheader is a pointer to a struct:

1
2
3
4
5
typedef struct LEVElHEADER{
//...
    uint16_t number_of_eggs;
//...
}levelheader_t;
When I try to compile it, I get these errors :
test.c:7:18: warning: value computed is not used
test.c:7:54: error: expected ';'  before ')' token

I just can't find the problem Huh?
Logged

My Nspire Ndless C projects:
calc84maniac
Epic z80 roflpwner
Coder Of Tomorrow
LV11 Super Veteran (Next: 3000)
*
Online Online

Gender: Male
Last Login: Today at 23:03:51
Date Registered: 28 August, 2008, 05:09:05
Location: Right behind you.
Posts: 2737


Total Post Ratings: +376

View Profile
« Reply #1 on: 07 September, 2011, 20:59:50 »
0

In a for loop, you need to separate the statements with semicolons, not commas.
Logged

"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman
lkj
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: Today at 22:21:24
Date Registered: 07 September, 2011, 20:05:25
Posts: 362

Topic starter
Total Post Ratings: +40

View Profile
« Reply #2 on: 07 September, 2011, 21:06:20 »
0

Thank you
Sometimes I make really silly mistakes...
Logged

My Nspire Ndless C projects:
t0xic_kitt3n
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: 13 May, 2013, 01:56:35
Date Registered: 16 June, 2010, 20:46:00
Location: w,x,y,z
Posts: 1583


Total Post Ratings: +32

View Profile
« Reply #3 on: 07 September, 2011, 22:42:16 »
0

You're not alone, I kept on doing that for a while too Tongue
Logged




██████  ██  ██  ███████           ████    ██    ██   ██ ███████
█ ██ █  ██  ██   ██   █          ██  ██  ████   ███ ███  ██   █
  ██    ██  ██   ██             ██   ██ ██  ██  ███████  ██    
  ██    ██  ██   ██  █         ██       ██  ██  ███████  ██  █
  ██    ██████   █████         ██       ██  ██  ██ █ ██  █████ 
  ██    ██  ██   ██  █         ██   ███ ██████  ██   ██  ██  █
  ██    ██  ██   ██             ██   ██ ██  ██  ██   ██  ██    
  ██    ██  ██   ██   █          ██  ██ ██  ██  ██   ██  ██   █
 ████   ██  ██  ███████           █████ ██  ██  ██   ██ ███████

Munchor
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: 13 June, 2013, 19:29:09
Date Registered: 16 October, 2010, 15:39:13
Location: Position
Posts: 6209


Total Post Ratings: +174

View Profile
« Reply #4 on: 07 September, 2011, 22:55:00 »
0

By the way, you used "++w", shouldn't it be "w++"? I've seen both being used but I can't understand the different.

EDIT: Oh wait, I got it (http://www.gamedev.net/topic/337133-i-vs-i/)
« Last Edit: 07 September, 2011, 22:55:29 by ephan » Logged
Ashbad
Guest
« Reply #5 on: 07 September, 2011, 23:01:59 »
0

By the way, you used "++w", shouldn't it be "w++"? I've seen both being used but I can't understand the different.

very different.  they both increment, but ++w applies before the value is taken into account, w++ applies after the whole line has been run through.
Logged
Tribal
Anti-Riot Squad
LV5 Advanced (Next: 300)
*
Offline Offline

Gender: Male
Last Login: 12 May, 2013, 02:02:17
Date Registered: 02 September, 2008, 22:38:51
Location: $0001
Posts: 237


Total Post Ratings: +13

View Profile
« Reply #6 on: 08 September, 2011, 06:32:30 »
0

By the way, you used "++w", shouldn't it be "w++"? I've seen both being used but I can't understand the different.

EDIT: Oh wait, I got it (http://www.gamedev.net/topic/337133-i-vs-i/)

Just as a side note, it is more efficient to do ++w.  So if you don't need the value of w before it's incremented, then use ++w instead.
Logged
calcdude84se
Needs Motivation
Members
LV11 Super Veteran (Next: 3000)
***********
Offline Offline

Gender: Male
Last Login: 14 May, 2013, 16:12:14
Date Registered: 21 April, 2010, 04:20:59
Posts: 2207


Total Post Ratings: +62

View Profile
« Reply #7 on: 08 September, 2011, 06:47:25 »
0

Just as a side note, it is more efficient to do ++w.  So if you don't need the value of w before it's incremented, then use ++w instead.
Except any good compiler will compile "w++" to the same as "++w" if the result isn't used. (I know the discussion ephan linked says that this might not be the case sometimes, but that's for C++) If precedent helps, I've always seen it written postfix for the loop increment.
Logged

"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Bug me about PartesOS. I might just need reminding.
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.253 seconds with 31 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.