| | |
for loop error
![]() |
i have this for loop in my program that i am creating but it is counting further than it is supposed to and trying to call to an unknown variable thus creating an error. here is the code that kicks back the error.
C Syntax (Toggle Plain Text)
for (i = 1; i <= me.spellcasterlevel; i++){ if (me.firelevel >= i){ //cout << i << ": " << me.fire[i].name << endl; } } cin >> choice;
Arrays are indexed from 0 to N-1, not 1 to N. The usual idiom is like this.
for ( i = 0; i < N; ++i )
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
C Syntax (Toggle Plain Text)
#include <stdio.h> int main() { int i, array[5] = {10,20,30,40,50}; puts("right"); for (i = 0; i < 5; ++i) { printf("array[%d] = %d\n", i, array[i]); } puts("wrong"); for (i = 1; i <= 5; ++i) { printf("array[%d] = %d\n", i, array[i]); } return 0; } /* my output right array[0] = 10 array[1] = 20 array[2] = 30 array[3] = 40 array[4] = 50 wrong array[1] = 20 array[2] = 30 array[3] = 40 array[4] = 50 array[5] = 1245112 */
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- Database Connectivity in C (C)
- Tic-Tac-Toe (C++)
- geforce 6600 hangs, reboot bsod (Monitors, Displays and Video Cards)
- Homework help - displaying a Chart (C++)
- c++ homework (C++)
Other Threads in the C Forum
- Previous Thread: String to integer to ascii
- Next Thread: win32
| Thread Tools | Search this Thread |
#include * adobe ansi array asterisks binarysearch centimeter changingto char character cm convert copyimagefile cprogramme creafecopyofanytypeoffileinc database dynamic execv feet fgets file floatingpointvalidation fork function getlogicaldrivestrin givemetehcodez global grade gtkwinlinux hacking histogram ide inches include incrementoperators infiniteloop input interest intmain() iso kernel keyboard kilometer license linked linkedlist linux locate logical_drives looping lowest match matrix meter microsoft number oddnumber opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer posix power probleminc process program programming radix recursion recv recvblocked research reversing segmentationfault sequential single socket socketprograming socketprogramming standard strchr string suggestions systemcall test threads turboc unix urboc user variable voidmain() wab whythiscodecausesegmentationfault windowsapi






