Actually, look again at that for-loop in my example:
Quote from: consoleActually, look again at that for-loop in my example: for (int i = 99; .............for (i = 0; i < note->GetTitle ().GetLength (); i++)the line above gave the error during compilation, well.. a few lines before. nowhere did i see "i" declared as a variable, but i figured it was declared somewhere, because i know C isn't like VB, so you have to say what type your variables are.
Actually, look again at that for-loop in my example: for (int i = 99; .............
void CMainFrame::CreateMinimizedMenu(BCMenu *pMainMenu, BCMenu *pMinimize){// Show the minimized notes on the system tray menu (max 20) pMainMenu->EnableMenuItem (6, MF_GRAYED | MF_BYPOSITION); for (int i = 0; i < 20; i++) pMinimize->RemoveMenu (0, MF_BYPOSITION); int iCount = 0; POSITION pos = m_pNotes.GetHeadPosition (); while (pos) { CNote *note = (CNote *) m_pNotes.GetNext (pos); if (!note->GetVisible () && iCount <= 20) { USES_CONVERSION; char *pTemp = (char *) malloc (note->GetTitle ().GetLength () + 1); for (i = 0; i < note->GetTitle ().GetLength (); i++) pTemp[ i ] = note->GetTitle ().GetAt (i); pTemp [note->GetTitle ().GetLength () + 1] = '\0'; TCHAR* szWide = A2T( pTemp ); delete pTemp; pMinimize->AppendMenu (MF_STRING ,ID_MINIMIZEDMENUITEM + iCount, szWide); pMainMenu->EnableMenuItem (6, MF_ENABLED | MF_BYPOSITION); iCount++; } }}
i understand C like this (it's been a while):in C you have to declare your variables, like x is an int, or a float, double, whatever. you can do this within a function, and they are local to the function, globally in function main, as well as some "extern" way, if you wish to use variables from another linked .o file? say you have two .c files and you use a variable declared in one .c file in the other .c file, you have to declare these variables as extern or something (or did this extern thing have to do with function prototypes)? you link the files together when you create your .exe, the .c files can work together, so you could call a function in myfunction.c from main.c . you would compile them, and then link the .o files. if the variable is in function main, every linked file can use the variable, but if it's not in main, it needs to be passed as extern, or the value of the variable passed back from the function. i don't expect a detailed answer, i was kinda wondering how correct this is. i'm gonna have to go back and learn most of this stuff, i did ok, but i never really got a good grasp of structures, and i always got the feeling if you wanted to code anything really good, you needed to use those things : P
i had pointers and all that stuff down, then i think they switched stuff up on me : ( .. like now there are classes, and methods - and i don't know what these things are : )
class BeerBar def initialize(num_bottles) @num_bottles = num_bottles end def any_beer_left? if @num_bottles >= 1 puts "#{@num_bottles} bottles of beer on the wall! #{@num_bottles} bottles of beer!" true else false end end def take_one @num_bottles -= 1 puts "Take one down, pass it around! #{@num_bottles} bottles of beer on the wall." endend# ok we've defined our BeerBar class, now let's construct an instance of the class and use it:bar = BeerBar.new(99)while bar.any_beer_left? bar.take_oneend
#include <stdio.h>class BeerBar { public: BeerBar (int num_bottles) : m_num_bottles(num_bottles) { } bool any_beer_left () { if (m_num_bottles >= 1) { printf("%d bottles of beer on the wall! %d bottles of beer!\n", m_num_bottles, m_num_bottles); } return m_num_bottles >= 1; } void take_one () { --m_num_bottles; printf("Take one down, pass it around! %d bottles of beer on the wall.\n", m_num_bottles); } protected: int m_num_bottles;};// ok we've defined our BeerBar class, now let's construct an instance of the class and use it:int main (){ BeerBar bar(99); while (bar.any_beer_left()) bar.take_one(); return 0;}
Main would have to pass the address of its variables to any subroutine that wanted to use them.