Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
freeing memory
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Frank Silvermann, post: 2468945"] Thanks all for replies. Apparently the parens matter. Here is my new version of main, with everything else unchanged from upthread: int main(void) { int m=8, n=3, i, j; int *p; /* all declarations in main need to be north of here */ /* seed srand with time */ srand(time(NULL)); /* call partition and examine returns */ printf("set has %d elements and %d partitions\n", m, n); for(i = 0; i < ITERATIONS; i++) { p = malloc((n)*sizeof(int)); p = partition(m,n); if (p = NULL) { printf("failure\n"); } printf("m in n chunks: "); /*for (j = 0;j < n; j++) { printf(" %d", p[j]); } printf("\n");*/ free (p); } return 0; } /*end source */ Couple of questions: 1) Do I have a memory leak? 2) The output is now commented out. It compiles but causes my OS to hang. I could send the error report and wait for the Unnamed Vendor to get back to me, but I'm not sure when hell is to freeze over. Anyways, besides the fact that the commented-out source doesn't produce behavior in the ensuing executable that I like, it looks childish, in particular in a language that was designed to hop around arrays. So this question is, what is an elegant way in C to print a smallish array of ints? frank [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
freeing memory
Top