c - Generating Fibonacci Numbers Using variable-Length Arrays Code Compiler Error -


Compile the error in vs2010 (Win32 console application template) for the code below. How can I fix this?

  Unsigned long-time sole Fibonacci [numFibs]; Error C2057: Expected Stable Expression  

Error C2466: Can not allocate an array of continuous size 0

Error C2133: 'Fibonacci': Unknown size

Full code is attached (This programming is a sample code in the C-3i book. None modified)

  Int main () {Int i, numfibs; Printf ("How can you make Fibonacci numbers (between 1 to 75)?"); Scanf ("% i", and numfibs); If (numfibs & lt; 1 || numfibs> 75) {printf ("bad number, sorry !!"); Return 1; Unsigned long time F. Fibonacci [numFibs]; Fibonacci [0] = 0; // Definition Fibonacci [1] = 1; For // (i = 2; i & lt; numfibs; ++ i) Fibonacci [i] = Fibonacci [i-2] + Fibonacci [i-1]; For (i = 0; i & lt; numfibs; ++ i) printf ("% 11u", fibonacci [i]); Printf ("\ n"); Return 0; }  

Which compiler are you using? And are you compiled as C or C ++? Variables-length is legal in Array C, but if you are using the old compiler (or compiling as C ++) they will not work.

As an alternative solution, you can use dynamic allocation:

  typedef unsigned long uint64; // Simply uint64 * Fibonacci = (uint64 *) malloc for convenience (sizeof (uint64) * numfibs); // {code here} // Finally: Free (Fibonacci); Return 0;  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -