RSS Forums RSS
Please support our C++ advertiser: Programming Forums

C and C++ Timesaving Tips

Join Date: Apr 2004
Posts: 3,809
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 147
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: C and C++ Timesaving Tips

  #23  
Sep 9th, 2005
That is a snippet. Did you copy and paste all of those parts together and #include <stdio.h>?

[edit]Or pick just the necessary parts for one of them?
#include <stdio.h>

#define ARRAYSIZE(x)  (sizeof(x)/sizeof(*(x)))

void fum(int *array, size_t size)
{
   size_t i;
   /* Initialize array. */
   for ( i = 0; i < size; ++i )
   {
      array[i] = i;
   }
   /* Perform calculations. */
   for ( i = 0; i < size; ++i )
   {
      array[i] *= 2;
   }
   /* Print array. */
   for ( i = 0; i < size; ++i )
   {
      printf("%d,", array[i]);
   }
   putchar('\n');
}

int main(void)
{
   int myarray[25];
   fum(myarray, ARRAYSIZE(myarray));
   return 0;
}

/* my output
0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,
*/
High Plains Blogger #plains #lounge ## I, for one, welcome our new socialist overlords.
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
 
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 7:37 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC