Hullo. I'm using Microsoft Visual Studio 2005.
void NoOfOrdinates(void)
{
int i, ord;
float value;
printf("Enter the number of ordinates: ");
scanf("%d", &ord);
for (i=1; i<=ord; i++)
{
printf("Enter the value of the ordinate: ");
scanf("%f", &value);
}
}
Anyone know how I can store the values so I can use them for later equations? Or is it too complicated since my program now only allows the user to enter 10 values.
I dunno Visual Studio... and it is damn long since I touched C...
1) Is there a main function elsewhere? Because if you are just merely calling this function, values initialised in this function will be deleted once you exited the function. If so, it would be better to pass a pointer from the main function for this function to store it in. Either that or return a value instead of being a void function.
2) It seems from your code that you can only store 1 value because float value can only store once. Everytime you scanf, you rewrite and rewrite the previous values. There are 2 ways to solve this:
a) you can implement a huge array, and store it in the array. However, this is rather inefficient as i) there may be portions of the arrays not used, leading to inefficiency, and ii) there may not be enough space if the number of ordinates required is larger than the array size.
b) you can initialise a pointer instead, and allocate a memory space equivalent to the number of ordinates required using the malloc function. However, it is important to deallocate the memory when you do not need it, ie, when you exit the whole program.
I only remember the methodology, the exact code cannot really remember... But they are easily available online.
ok thks eagle!
but my project is over oledi so... ![]()
Originally posted by cApitaland:ok thks eagle!
but my project is over oledi so...
Then u check back so late... -.-
haha... solved? i know programming though ![]()
i know C only lah...use arrays can already...
finish liao ah? this mean i am too late to show off my programming liao loh??? haha...