Re: C input?

Alright so here it goes, though you could ask Dr. Google for more fancy schmancy stuff, but generally in C/C++ you have memory management. This means that variable allocation is divided into two primary parts. Stack and heap. The stack part is where you usually define your static variables, and what I mean by static is that the space for the variable is already predetermined in compile time. But then you have the heap part and there comes a dynamic allocation where the space is allocated during run time and you could dynamically alter the space as long as you play by the rules. So, in order to access a dynamically allocated  variable you have to use pointers or references. Basically what this means is that you define a variable name of type int eg, and using the * after the type would turn it to a pointer. Now you have to point this variable in the right direction, which is the space you have allocated for it. Generally you could use pointers/references to point to anywhere you want, it shouldn't necessarily be a dynamically reserved space. In C, malloc is the function which you allocate memory, free is the function which you deallocate memory. What post 5 means by passing a pointer to the input function is something like int getIntInput(bool* OK). Then in the function body you could do something like
    if(scanf("%d%c", &a, &term) != 2 || term != '\n')
    {
        *OK=false; //* is the dereference operator. It says something like "hey, go to this guy's location and set his value to *false." Although you have to pass an already allocated bool to it, otherwise what you dereference could be some random *block, which would piss your computer off, resulting in unexpected crashes/ horrible memory leaks/ etc.
    }
Look at This page to see this in action.

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : stewie via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : stewie via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : philip_bennefall via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : leibylucw via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : mechaSkyGuardian via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : leibylucw via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : gonzalez via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : thggamer via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : kaigoku via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : leibylucw via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector

Reply via email to