C and C++ Timesaving Tips

Closed Thread

Join Date: Oct 2004
Posts: 3,872
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 870
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: C and C++ Timesaving Tips

 
0
  #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!
Quick reply to this message  
Join Date: Sep 2005
Posts: 41
Reputation: rakoon13 is an unknown quantity at this point 
Solved Threads: 1
rakoon13 rakoon13 is offline Offline
Light Poster

Re: C and C++ Timesaving Tips

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

When I use:

  1. void fum(int *array, size_t size)
  2. {
  3. size_t i;
  4. /* Initialize array. */
  5. for ( i = 0; i < size; ++i )
  6. {
  7. array[i] = i;
  8. }
  9. /* Perform calculations. */
  10. for ( i = 0; i < size; ++i )
  11. {
  12. array[i] *= 2;
  13. }
  14. /* Print array. */
  15. for ( i = 0; i < size; ++i )
  16. {
  17. printf("%d,", array[i]);
  18. }
  19. putchar('\n');
  20. }
  21.  
  22. int main(void)
  23. {
  24. int myarray[25];
  25. foo();
  26. bar();
  27. baz();
  28. qux();
  29. fum(myarray, ARRAYSIZE(myarray));
  30. return 0;
  31. }
<< 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
Quick reply to this message  
Join Date: Apr 2004
Posts: 4,321
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 230
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: C and C++ Timesaving Tips

 
0
  #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?
  1. #include <stdio.h>
  2.  
  3. #define ARRAYSIZE(x) (sizeof(x)/sizeof(*(x)))
  4.  
  5. void fum(int *array, size_t size)
  6. {
  7. size_t i;
  8. /* Initialize array. */
  9. for ( i = 0; i < size; ++i )
  10. {
  11. array[i] = i;
  12. }
  13. /* Perform calculations. */
  14. for ( i = 0; i < size; ++i )
  15. {
  16. array[i] *= 2;
  17. }
  18. /* Print array. */
  19. for ( i = 0; i < size; ++i )
  20. {
  21. printf("%d,", array[i]);
  22. }
  23. putchar('\n');
  24. }
  25.  
  26. int main(void)
  27. {
  28. int myarray[25];
  29. fum(myarray, ARRAYSIZE(myarray));
  30. return 0;
  31. }
  32.  
  33. /* my output
  34. 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,
  35. */
"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
Quick reply to this message  
Join Date: Sep 2005
Posts: 41
Reputation: rakoon13 is an unknown quantity at this point 
Solved Threads: 1
rakoon13 rakoon13 is offline Offline
Light Poster

Re: C and C++ Timesaving Tips

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

Re: C and C++ Timesaving Tips

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

Ashwin Perti
Quick reply to this message  
Join Date: Apr 2004
Posts: 4,321
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 230
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: C and C++ Timesaving Tips

 
0
  #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.
"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
Quick reply to this message  
Join Date: Aug 2005
Posts: 22
Reputation: ashwinperti is an unknown quantity at this point 
Solved Threads: 0
ashwinperti ashwinperti is offline Offline
Newbie Poster

Re: C and C++ Timesaving Tips

 
0
  #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
Quick reply to this message  
Join Date: Apr 2004
Posts: 4,321
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 230
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: C and C++ Timesaving Tips

 
0
  #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.
"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
Quick reply to this message  
Join Date: Sep 2005
Posts: 41
Reputation: rakoon13 is an unknown quantity at this point 
Solved Threads: 1
rakoon13 rakoon13 is offline Offline
Light Poster

Re: C and C++ Timesaving Tips

 
0
  #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
Quick reply to this message  
Join Date: Mar 2006
Posts: 163
Reputation: grunge man is an unknown quantity at this point 
Solved Threads: 2
grunge man grunge man is offline Offline
Junior Poster

Re: C and C++ Timesaving Tips

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

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC