and remove the for focus for loop?
and remove the for focus for loop?
nevermind.
i did it anyway.
still wont print anything out.
gahhh. getting annoyed now.
I don't see anything wrong in that code. Try to add some debug output in various places (e.g. uncomment your printf when you set valid = 1 to see if it gets there.
You may want to add a "\n" to the end of "error" to make it look better - this shouldn't make any difference to the execution of the code.
--
Mats
well i tried this
but it still didnt print out anything.Code:for (j=0;j<(sizeof(validaperture) / sizeof(validaperture[0]));j++) { if ((validfocus == focus)&&(aperture == validaperture[j])) { fprintf(output,"the aperture value is correct"); valid = 1; } }
what does this mean.
it now semi works.
it compiles.
and when i type any of the correct values it will print the correct value.
and if the number is not correct it will print and error
buut if it does not recieve the 'f' it will sit for about 10min without doing anything.
by then i got frustrated of waiting and suspending it.
if you want the full code i can send it to you,
but i cannot afford for others in my class to steel the full code as i can be done for plagerism.
im so close now.
just quiet get it.
Are you checking to see if you have the right number of values back from fscanf(), like I suggested on Friday?
--
Mats
yeh ive tried it.
its even in my code atm.
but for some reason even if i dont enter two values it wont work.
No, what I'm trying to make you do is get an error message if there's the wrong number of things for fscanf to operate correctly.
Note also that fscanf is prone to "messing up" your input. Perhaps a better approach is to read using fgets() and using the result of fgets() to feed into sscanf() - the problem here is that if fscanf() is fed "bad stuff", then it willl just sit there refusing to get any data in at all. Say for example you are trying to read with scanf("%d"), and the current input is "a", then it will not progress past the a EVER! It's stuck.
--
Mats
we dont use fgets.
i dont know if im allowed to use it. only what ive been tought.
would fflush do anything?
fflush is invalid on input streams, so no.
If they are telling you to use fscanf(), then you have to live with that. But you need to make sure that your input is exactly where you're expecting it.
Is it a real requirement to read in "f1.2" rather than "1.2" for teh aperture? It may simplify things a lot if you don't attempt to read the "f" part (and if you do, try to make sure your code accepts both "f" and "F").
--
Mats
yes they want the f. which makes it so much harder. ive got it so close.
this sucks.
Are you allowed to use sscanf()? If so, you could use something like:
Note that as opposed to fgets(), any version of scanf is not resistant to "buffer overflow". And strange things may happen if someone enteres "f1f" or some such.Code:char str[100]; ... fscanf(f, "%s", str); if (tolower(str[0]) == 'f' && isdigit(str[1])) { sscanf(&str[1], "%f", &aperture); ... } ...
--
Mats
i want to know why res doesnt kick in when it should.
ive even tried 1.2f.
that freezes to.
f1f but will print the error message.