Thread: new to C. need basic help

  1. #61
    Registered User
    Join Date
    Aug 2007
    Posts
    46
    and remove the for focus for loop?

  2. #62
    Registered User
    Join Date
    Aug 2007
    Posts
    46
    nevermind.
    i did it anyway.

    still wont print anything out.

    gahhh. getting annoyed now.

  3. #63
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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

  4. #64
    Registered User
    Join Date
    Aug 2007
    Posts
    46
    well i tried this

    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;
        }
       }
    but it still didnt print out anything.
    what does this mean.

  5. #65
    Registered User
    Join Date
    Aug 2007
    Posts
    46
    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.

  6. #66
    Registered User
    Join Date
    Aug 2007
    Posts
    46
    im so close now.

    just quiet get it.

  7. #67
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Are you checking to see if you have the right number of values back from fscanf(), like I suggested on Friday?

    --
    Mats

  8. #68
    Registered User
    Join Date
    Aug 2007
    Posts
    46
    yeh ive tried it.

    its even in my code atm.
    but for some reason even if i dont enter two values it wont work.

  9. #69
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by k4k45hi View Post
    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

  10. #70
    Registered User
    Join Date
    Aug 2007
    Posts
    46
    we dont use fgets.
    i dont know if im allowed to use it. only what ive been tought.

    would fflush do anything?

  11. #71
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by k4k45hi View Post
    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

  12. #72
    Registered User
    Join Date
    Aug 2007
    Posts
    46
    yes they want the f. which makes it so much harder. ive got it so close.

    this sucks.

  13. #73
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by k4k45hi View Post
    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:
    Code:
    char str[100];
    ...
    
    fscanf(f, "%s", str); 
    if (tolower(str[0]) == 'f' && isdigit(str[1])) { 
       sscanf(&str[1], "%f", &aperture);
       ...
    }
    ...
    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.

    --
    Mats

  14. #74
    Registered User
    Join Date
    Aug 2007
    Posts
    46
    i want to know why res doesnt kick in when it should.

  15. #75
    Registered User
    Join Date
    Aug 2007
    Posts
    46
    ive even tried 1.2f.

    that freezes to.

    f1f but will print the error message.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 10:28 AM
  2. what are your thoughts on visual basic?
    By orion- in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-22-2005, 04:28 AM
  3. visual basic vs C or C++
    By FOOTOO in forum Windows Programming
    Replies: 5
    Last Post: 02-06-2005, 08:41 PM
  4. Basic Graphics programming in C, please help
    By AdRock in forum Game Programming
    Replies: 3
    Last Post: 03-24-2004, 11:38 PM