User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 374,018 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,671 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 48171 | Replies: 54
Closed Thread
Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,333
Reputation: vegaseat is on a distinguished road 
Rep Power: 8
Solved Threads: 170
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
Kickbutt Moderator

Solution Re: C and C++ Timesaving Tips

  #21  
Aug 29th, 2005
Put a newline at the end of the file ...
Didn't give me the extra 10.
Why should a newline give an extra 10?
May 'the Google' be with you!
 
Join Date: Sep 2005
Location: ga
Posts: 39
Reputation: rakoon13 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
rakoon13 rakoon13 is offline Offline
Light Poster

Re: C and C++ Timesaving Tips

  #22  
Sep 9th, 2005
Something is not right.

When I use:

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];
   foo();
   bar();
   baz();
   qux();
   fum(myarray, ARRAYSIZE(myarray));
   return 0;
}
<< moderator edit: added [code][/code] tags and indenting >>

I have several errors. This is the exact replica of one of the posts above.
I don't understand where is the mistake as all looks ok.


Thanks,
Steven Dale
 
Join Date: Apr 2004
Posts: 3,418
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 
Rep Power: 15
Solved Threads: 137
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,
*/
 
Join Date: Sep 2005
Location: ga
Posts: 39
Reputation: rakoon13 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
rakoon13 rakoon13 is offline Offline
Light Poster

Re: C and C++ Timesaving Tips

  #24  
Sep 9th, 2005
copy-paste
 
Join Date: Aug 2005
Posts: 22
Reputation: ashwinperti is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
ashwinperti ashwinperti is offline Offline
Newbie Poster

Re: C and C++ Timesaving Tips

  #25  
Sep 15th, 2005
What is the use of size_t . When we can use int for the same work to do.

Ashwin Perti
 
Join Date: Apr 2004
Posts: 3,418
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 
Rep Power: 15
Solved Threads: 137
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: C and C++ Timesaving Tips

  #26  
Sep 15th, 2005
A size_t is an unsigned integral type which is the result of the sizeof operator. The two are designed to go together. To me it's the type most suited to indexing an array (you don't need negative indexes, do you?).

Sure you could use an int and it will be correct 99.999% of the time -- I was just going for 100%. Plus, with an array of ints, I find it easier to see the index from the data if they're not just slopped together.
 
Join Date: Aug 2005
Posts: 22
Reputation: ashwinperti is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
ashwinperti ashwinperti is offline Offline
Newbie Poster

Re: C and C++ Timesaving Tips

  #27  
Sep 16th, 2005
I could not understand how exactly we can change the dimension of the array dynamically. Size once taken cannot be changed during the course of the program.

Ashwin Perti
 
Join Date: Apr 2004
Posts: 3,418
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 
Rep Power: 15
Solved Threads: 137
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: C and C++ Timesaving Tips

  #28  
Sep 16th, 2005
It is not in regard to changing an array's size dynamically. It is in regard to recompiling on different systems.
 
Join Date: Sep 2005
Location: ga
Posts: 39
Reputation: rakoon13 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
rakoon13 rakoon13 is offline Offline
Light Poster

Re: C and C++ Timesaving Tips

  #29  
Sep 19th, 2005
I think you ppl lost me there. I am not a wizard, however I do used to belive you can change the size during the program is running .


Clara Ventures
www.cellforum.net
 
Join Date: Mar 2006
Posts: 147
Reputation: grunge man is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 2
grunge man grunge man is offline Offline
Junior Poster

Re: C and C++ Timesaving Tips

  #30  
Apr 1st, 2006
um how does the vector in c++ compare to the vector in physics
 
Closed Thread

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 11:04 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC