hahaha yea man, thats how tutor teaches.
for the pseudocode i mean for this bit:
apertureNo = atof(&aperture[1]);
i guess to extract the digits from the array?
Printable View
hahaha yea man, thats how tutor teaches.
for the pseudocode i mean for this bit:
apertureNo = atof(&aperture[1]);
i guess to extract the digits from the array?
You already have C code, why do you need pseudo-code? . . .
Are you wondering how atof() works? It probably does something like this:Code:number = string_to_number(string from element 1 onwards)
That's just one way to do it, of course. A way I haven't tested. I suppose you want its pseudo code. :)Code:#include <ctype.h>
float my_atof(const char *s) {
float f = 0.0f, fraction = 0.0f;
while(*s) {
if(isdigit(*s)) {
f *= 10;
f += *s - '0';
fraction *= 10;
}
else if(*s == '.') {
fraction = 1;
}
else break;
}
if(fraction) f /= fraction;
return f;
}
Something like that.Code:for each character in the string
if the character is a digit
multiply the number by 10 to shift all of the other digits to the left
add the digit to the number
else if the character is a decimal
take note of the position of the decimal point
else the character is unrecognized, so end the loop
if a decimal point was noted, shift the number right \
enough times to put the decimal place where it belongs
return the number
ya well first i have to write pseudocode then program, i just wanted to see if there was a way to get the number from string and now there is.
theres no other simple pseudocode to describe getting the number from string? because yours sound too much like proper english??
I dislike very specific pseudo-code. In my opinion, if you've got the program nailed down to a high enough degree to write very specific pseudo-code, you might as well write C.Quote:
theres no other simple pseudocode to describe getting the number from string? because yours sound too much like proper english??
If you want really specific pseudo-code, just convert my C code into it. :) As long as you understand it, converting it to pseudo-code should be quite simple.
If you don't understand it, study the vague pseudo-code that I posted, or look elsewhere. :)
I agree. And pseudo-code isn't a standardized "language" (in the way that C/C++ is), you may do as you like in it. Different companies, universities or such may have definitions of their pseudo-code form. Where I worked previously, the pseudo-code looked pretty much like C, but it had some non-C "operations" that made it easier to write the pseudo-code [can't remember the exact details, as it was a while back, and I only read the pseudo-code, as it was written by the high-level architects].
If Taurus' school has a defined standard for pseudo-code, then the code dwks wrote should be fairly easy to translat inot that.
I'm also going to add that wriitng your own "atof" is probably not a good idea, but that's a different discussion.
--
Mats
i used this:
char aperture[4] (=f1.2)
int app
app = atof(aperture[1]);
Now i get an error for the atof?? whats wrong?
(error is: passing argument 1 of atof makes pointer from integer without cast)
what can i do?
ok correction . wen i use aperture + 1 it works. Now app is an int and i get my result of 1 from f1.2 but not the .2. But once app is double it gives a random number of 858993459
how can i get the .2???
thanks
use %f format to print double
ah right thanks