•
•
•
•
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
![]() |
•
•
Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,333
Reputation:
Rep Power: 8
Solved Threads: 170
Put a newline at the end of the file ...
Didn't give me the extra 10.
Why should a newline give an extra 10?
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:
Rep Power: 3
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:
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?
#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:
Rep Power: 3
Solved Threads: 1
copy-paste
•
•
Join Date: Aug 2005
Posts: 22
Reputation:
Rep Power: 3
Solved Threads: 0
What is the use of size_t . When we can use int for the same work to do.
Ashwin Perti
Ashwin Perti
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.
•
•
Join Date: Aug 2005
Posts: 22
Reputation:
Rep Power: 3
Solved Threads: 0
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
Ashwin Perti
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:
Rep Power: 3
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
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
- 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: Alternative for cout << "";


Linear Mode