| | |
Array question
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2008
Posts: 48
Reputation:
Solved Threads: 0
Hello.,
Have a question about array being set from function argument. I wrote this little program, and want to know why cant i set an array size from the function argument. Any help would be greatly appreciated.
---
Andre Granovsky
Have a question about array being set from function argument. I wrote this little program, and want to know why cant i set an array size from the function argument. Any help would be greatly appreciated.
C Syntax (Toggle Plain Text)
int money(int deposit, ...){ int i, sum = 0, nextvar; // myArr[deposit]; // < -- in here i cant set the array size from function receiving argument? and why? va_list parg; va_start(parg, deposit); for(i=0;i<deposit;i++){ nextvar=va_arg(parg, int); // myArr[i]=nextvar; sum+=nextvar; } va_end(parg); return sum/deposit; } int main(void){ printf("%d", money(4,4,4,4,4)); getchar(); return 0; }
---
Andre Granovsky
"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
>static arrays are ............
You meant to say "fixed-length" arrays, right?
OP>in here i cant set the array size from function receiving argument? and why?
Because, array size should be a compile time constant, that is: the array size should be known at the compile time. You are already been told what is the solution by Dave.
You meant to say "fixed-length" arrays, right?
OP>in here i cant set the array size from function receiving argument? and why?
Because, array size should be a compile time constant, that is: the array size should be known at the compile time. You are already been told what is the solution by Dave.
Siddhant Sanyam
(Not posting much)
My Blog: Yatantrika
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
(Not posting much)
My Blog: Yatantrika
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
![]() |
Similar Threads
- Little Simple array question :) (C)
- Simple array question (C++)
- Simple char array question (C)
- Newbie Constructor / Array question (C++)
- Array Question (C++)
- C++ Array Question (C++)
- array question (C++)
Other Threads in the C Forum
- Previous Thread: size of a file
- Next Thread: How can i more control rand()
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char convert copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax directory drawing dynamic fflush file fork forloop frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop interest kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix problem probleminc program programming pyramidusingturboccodes radix recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socketprograming spoonfeeding stack standard string strings structures student systemcall testautomation turboc unix user variable voidmain() wab windows.h






