| | |
C and C++ Timesaving Tips
![]() |
•
•
Join Date: Sep 2005
Posts: 41
Reputation:
Solved Threads: 1
Something is not right.
When I use:
<< 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
When I use:
C++ Syntax (Toggle Plain Text)
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; }
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
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?
[edit]Or pick just the necessary parts for one of them?
C++ Syntax (Toggle Plain Text)
#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, */
"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
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.
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
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
•
•
Join Date: Sep 2005
Posts: 41
Reputation:
Solved Threads: 1
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
Clara Ventures
www.cellforum.net
![]() |
Similar Threads
- Timesaving Tips (C++)
- Response to time saving tips sticky (C++)
Other Threads in the C++ Forum
- Previous Thread: not sure why program crashes
- Next Thread: helpppppp me with this program
| Thread Tools | Search this Thread |
api array based binary bitmap business c++ c/c++ char class classes code coding commentinghelp compile console conversion count decide delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez graph guess gui homeworkhelp homeworkhelper iamthwee ifpug ifstream incrementoperators infinite input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem proficiency program programming project python random read recursion reference rpg string strings temperature template templates test text text-file tree url variable vector video win32 windows winsock word wordfrequency wxwidgets





