Help With Simple Program...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Narc0
    New Member
    • Jan 2007
    • 18

    Help With Simple Program...

    Hello everyone,

    I have a problem with a rather simple thing. I have to make the code of a program. The program is already made, I have the executable and all, the only thing I need is the source code(in C). The problem is, I don't really know how to do it.

    All the program does is tell you when a light is on or off. It has four switches and a battery. If only one switch is on, then the light is off. If any combination of the four switches(if two are on), then the light is ON. Can somebody help me taking out the code from the executable?

    To make the program work, you have to open it in MSDOS and type the name of the program(demoTL0 1) and then the number of the switch to tell it's on... so for example:

    demoTL01 1

    Tells the program that only the first switch is on, making the light off.

    demoTL01 1 2

    Tells the program that the first two switch are on, making the light on.

    Etc..

    Here it is(if you want it, scan it first) and please right click and save as it:

    http://www.angelfire.c om/wrestling3/roleplays0/demoTL01.exe

    THANKS!!!
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    Do you have a question about a particular section in your code? You should post the source code for the executible or what your assignment is and not ask us to download an .exe. Have you tried to solve this yet? What have you accomplished so far? If you are better prepared and have tried to solve your problem first then it is more likely you will get help from someone later.

    Comment

    • Narc0
      New Member
      • Jan 2007
      • 18

      #3
      Originally posted by RedSon
      Do you have a question about a particular section in your code? You should post the source code for the executible or what your assignment is and not ask us to download an .exe. Have you tried to solve this yet? What have you accomplished so far? If you are better prepared and have tried to solve your problem first then it is more likely you will get help from someone later.
      That's what I need: the source code from that executable or a way to replicate that same thing. The problem is I don't even know where to start. So I need help from you guys.

      Thanks!

      Comment

      • nickyeng
        Contributor
        • Nov 2006
        • 252

        #4
        Originally posted by Narc0
        That's what I need: the source code from that executable or a way to replicate that same thing. The problem is I don't even know where to start. So I need help from you guys.

        Thanks!
        If there is a way to form an executable file back into source code, I would have done it but yet it dont exist.

        correct me if i'm wrong.
        If somehow can make an executable file back into source code, please tell me.
        :-)

        from
        Nick

        Comment

        • Motoma
          Recognized Expert Specialist
          • Jan 2007
          • 3236

          #5
          In order for us to be helpful, you need to be helpful as well.
          In clear English, describe what you are trying to accomplish, as well as what steps you have taken to do so. Delineate the problems you have encountered, as well as your ideas as to what the cause of the problems are. Include source code, with as much commenting as you are able to provide.

          Comment

          • Narc0
            New Member
            • Jan 2007
            • 18

            #6
            Again, I haven't even started because I don't know how to.

            What I want is someone to reproduce the thing in that .exe. Exactly the same thing.

            Comment

            • Motoma
              Recognized Expert Specialist
              • Jan 2007
              • 3236

              #7
              Originally posted by Narc0
              Again, I haven't even started because I don't know how to.

              What I want is someone to reproduce the thing in that .exe. Exactly the same thing.
              Okay, so what, exactly, does this program do? You mention switches, are these switches the arguments you pass to the program on the command line, or are they physical switches plugged into one of the various ports of the computer? You mention that it tells you if a light is on or off, where is this light? And how does it 'tell' you?

              Comment

              • DeMan
                Top Contributor
                • Nov 2006
                • 1799

                #8
                Some tips (I shall assume you know at least the C Basics):

                in the main method of your program (you know the one called main) you are passed an array o command line arguments:

                int main (char args[]) //or however you want to call them
                you need to parse args to tell which switches are selected.

                You say when (any?) two are selected, the light is on, consider what the behaviour is for three, or four.

                I am assuming (because angelfire quite wisely does not allow me to download executable files) that the output simply says "Light is ON" in whcih case a simple printf will do the trick.

                If you do not understand what the main method even is, I would suggest you got to Banfa's tutorial http://www.thescripts.com/forum/thread570739.html

                Comment

                • Narc0
                  New Member
                  • Jan 2007
                  • 18

                  #9
                  Guys, if you download the .exe(right click and save as), and follow the instructions on my first post, you'll know what the program does. And all I want is a code that does exactly that, nothing more.

                  THANKS!

                  Comment

                  • Motoma
                    Recognized Expert Specialist
                    • Jan 2007
                    • 3236

                    #10
                    Originally posted by Narc0
                    Guys, if you download the .exe(right click and save as), and follow the instructions on my first post, you'll know what the program does. And all I want is a code that does exactly that, nothing more.

                    THANKS!
                    I'm sorry, I tried downloading the file as the first step to helping you, but I came to a page which states:

                    Angelfire does not allow downloading
                    of certain file types to protect
                    visitors from computer viruses.
                    If you could give us a written description, including the things I asked for in the my previous post, I will do what I can to help.

                    Comment

                    • Narc0
                      New Member
                      • Jan 2007
                      • 18

                      #11
                      Did you try right clicking it and saving as? That's what I did and it works. If not, then it's on geocities too... right click and save as...

                      http://yoyirod.googlep ages.com/demoTL01.exe

                      THANKS!

                      Comment

                      • Motoma
                        Recognized Expert Specialist
                        • Jan 2007
                        • 3236

                        #12
                        Originally posted by Narc0
                        Did you try right clicking it and saving as? That's what I did and it works. If not, then it's on geocities too... right click and save as...

                        http://yoyirod.googlep ages.com/demoTL01.exe

                        THANKS!
                        Psuedo-Code, guarenteed not to work properly:
                        Code:
                        #include <stdio.h>
                        int main(int argc, char* argv[])
                        {
                          int num = 0;
                          for(int i = 1; i <= argc; i++)
                            if(argv[i] == '1' || argv[i] == '2' || argv[i] == '3' || argv[i] == '4')
                              num++;
                            else
                              printf("%s?!?  That isn't one of the switches!", argv[i]);
                          if(num > 1) printf("%s","Let there be light.");
                          else printf("%s","Let there be night.");
                          return 0;
                        }
                        This was whipped up in a matter of seconds, and still requires some more refining: for instance, if the user specifies that switch 1 is on twice (i.e. Light.exe 1 1 1 1 1) it will register as being on.

                        Comment

                        • Narc0
                          New Member
                          • Jan 2007
                          • 18

                          #13
                          I compiled it and there is a problem in the "for" line. It says for declaration used outside C99 Mode. Any more help or finishing that code would be very helpful.

                          THANKS!

                          Comment

                          • Motoma
                            Recognized Expert Specialist
                            • Jan 2007
                            • 3236

                            #14
                            Originally posted by Narc0
                            I compiled it and there is a problem in the "for" line. It says for declaration used outside C99 Mode. Any more help or finishing that code would be very helpful.

                            THANKS!
                            It's only pseudo-code, it wasn't made to compile...I wrote it to show you the basic flow of the program, as well as how to utilize the arguments from the command line.

                            The error you are getting sounds like a compiler error...What compiler are you using? Are you working with an IDE as well? The more information you give me, the more I can help you out.

                            Comment

                            • Narc0
                              New Member
                              • Jan 2007
                              • 18

                              #15
                              Bloodshed's Dev-C++. I need a source code because I don't know how to code it.

                              Comment

                              Working...