Thread: C problem (simple)

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    54

    C problem (simple)

    I need to write a program where i need to do the following:
    "1) Prompt for and then accept an exposure time.
    2) Prompt for and then accept an aperture.
    3) If the aperture is not one of the acceptable aperture values then an error is reported and the program exits.
    4) The exposure time and aperture is then printed out with a suitable heading."

    This is all easy except the values for aperture are f1.2, f2 etc i dont know if that is a string or int or double or watever. some one told me i must use strcmp but i dont know how.... plz help

    Thanks

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    There's been AT LEAST three other threads, so if instead of posting, you go search the forum and look at those - searching for "aperture" will probably get you there - but of course, you won't actually learn much that way, but that's not my problem.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    54
    oh yeah true.

    Wow you have posted quite a bit...thanks...

    by the way i dono why we use stdin stdout fprintf blah blah when we can use the standard printf...hmm

    anyway the teacher is using a program to test our codes, so its not done manually i dont think, i was wondering if there is anyway to crack it or trick it in anyway...

    Thanks

  4. #4
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    i was wondering if there is anyway to crack it or trick it in anyway...
    No one here's going to help you cheat. That wouldn't really be helping you, now would it ?

    Your teacher might be making you use fprintf to prepare you for file output, but that would definitely be an odd decision.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  5. #5
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by juststartedC View Post
    i was wondering if there is anyway to crack it or trick it in anyway...
    You can wonder all you want

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by juststartedC View Post
    anyway the teacher is using a program to test our codes, so its not done manually i dont think, i was wondering if there is anyway to crack it or trick it in anyway...
    some people here don't want to help you do something "unethical". But I'll help you!!

    First, go to this page and download a C89 or C99 draft. Find the section called "Undefined Behavior" and choose something really obscure.

    then implement it in you program. kind of like this
    Code:
    int main()
    {
        /* code */
    
        {
            int *p;
            srand(time(NULL)); /* seed rand */
            *p=rand();
        }
        return 0;
    }
    the beauty of this program (besides its simplicity) is that your teacher has no way of knowing what the program will do until it's too late!

    make sure to
    Code:
    #include <time.h>
    #include <stdlib.h>
    at the beginning of your program.
    Thanks
    you're welcome!
    Last edited by robwhit; 09-11-2007 at 10:32 AM.

  7. #7
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    Quote Originally Posted by juststartedC View Post
    by the way i dono why we use stdin stdout fprintf blah blah when we can use the standard printf...hmm
    fprintf is the standard. printf just ends up calling fprintf behind the scenes with stdin supplied for you.

  8. #8
    Registered User
    Join Date
    Sep 2007
    Posts
    54
    Thanks alot for the crack rob.

    What exactly does it do though? will it give me full marks for my code or.....

    Also do i write my own code where it says /* code */ ???

    ta

  9. #9
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    /me shakes head sadly
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  10. #10
    Registered User
    Join Date
    Sep 2007
    Posts
    54
    look i know i wont learn this way but the truth is im doing engineering and this is the only programming unit we will ever do in 4 years of university. it is quite difficult for me and i was just hoping to get it over and done with

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by juststartedC View Post
    look i know i wont learn this way but the truth is im doing engineering and this is the only programming unit we will ever do in 4 years of university. it is quite difficult for me and i was just hoping to get it over and done with
    So you don't actually WANT to learn the stuff, right? That's a pretty poor attitude. You will most likely find that knowing at least some programming will help you in the future, because almost every engineering job you can think of involves using computers. Understanding what makes the computer work will help you understand how to make it work better for you.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    Registered User
    Join Date
    Sep 2007
    Posts
    54
    No i didnt mean it quite like that. Ofcourse id like to learn something new specially programming which is very useful these days. its just that we are not being taught or helped much and we are expected to write codes, its really frustrating...

  13. #13
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by juststartedC View Post
    Thanks alot for the crack rob.

    What exactly does it do though? will it give me full marks for my code or.....
    probably the second one. but maybe you already know that by now.

    undefined behavior means that the C standard doesn't place limitations on what it could do. but most likely it would crash.
    Also do i write my own code where it says /* code */ ???

    ta
    yes.

    if you really want to learn C or C++ and you don't have a good instructor, click here, and ask any questions on the forum.

  14. #14
    Registered User
    Join Date
    Sep 2007
    Posts
    54
    Wow that is a useful link. thanks for that i actually starting to understand now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A simple file I/O problem
    By eecoder in forum C Programming
    Replies: 10
    Last Post: 10-16-2010, 11:00 PM
  2. Problem in simple code.
    By richdb in forum C Programming
    Replies: 6
    Last Post: 03-20-2006, 02:45 AM
  3. Problem in very simple code
    By richdb in forum C Programming
    Replies: 22
    Last Post: 01-14-2006, 09:10 PM
  4. Simple Initialization Problem
    By PsyK in forum C++ Programming
    Replies: 7
    Last Post: 04-30-2004, 07:37 PM
  5. Simple OO Problem
    By bstempi in forum C++ Programming
    Replies: 1
    Last Post: 04-30-2004, 05:33 PM