Tellalca 19 Posting Whiz in Training

What about NetBeans, I love its code formation. If using linux you may want to try Geany too.

Tellalca 19 Posting Whiz in Training

I am just trying to learn some javascript, not to validate email. Can you see the problem with my code?

Tellalca 19 Posting Whiz in Training

Hey;

I am learning some javascript. I tried to write a trivial code to validate email but my code does not seem to work it should.

It should turn the background color of text box green when mail contains both '@' and '.' characters and red otherwise. However what the code does is turning it to green whenever there is a '@' not caring about the '.'.

What is wrong with the code ?

function CheckMail()
        {
            var box = document.getElementById("email");
            var mail = box.value;
            
            var valid = true;
            if((mail.search("@") == -1) || (mail.search(".") == -1)) // If mail contains "@" and "." it is valid
                valid = false;
            
            if(valid)
            {
                box.style.background = "green";
            }
            else
            {
                box.style.background = "red";
                
            }
        }
Tellalca 19 Posting Whiz in Training

I have developed a program where I do some database connections and send some queries with JDBC to MySQL database called ANU.

I have used NetBeans 6.9 under Ubuntu 11.04 as platform. When I run the app from NetBeans, it works perfectly but when I try to run it from terminal I get SQL Exception. This is the function that produces that SQL Exception. The program terminates before "Establish is ending" line.

public Connection Establish(String iname, String ipassword) throws SQLException
    {
        System.out.println("Establish...");
        if(conn == null) // conn is a Connection object in the same class with this func
        {
            conn = DriverManager.getConnection("jdbc:mysql://localhost/ANU",
                    iname, ipassword);
        }
        else
            System.out.println("Connection Already Established!");
        System.out.println("Establish is ending...");
        return conn;
    } // End of Establish
Tellalca 19 Posting Whiz in Training

Selam, hoş geldin.

You can learn many things from DaniWeb, especially when you start helping others. Do not forget to checkout other related sites too.

Always stay with GNU and Linux.

Tellalca 19 Posting Whiz in Training

Scripting is programming too, even when you set your watch's alarm you are actually programming.

But generally scripting means writing some commands run line by line, not compiled.

Programming generally means writing some heavy weight code that is compiled into machine code.

Tellalca 19 Posting Whiz in Training

It's worse to use "int main(int argv, char** args)" because you loose two variable names if you won't use command line arguements or if the system does not support it .)

Tellalca 19 Posting Whiz in Training
Tellalca 19 Posting Whiz in Training

I don't know Phyton but here is the algorithm

counter = 0

while : number >= 1
number = number / 10
counter = counter + 1

print counter

Tellalca 19 Posting Whiz in Training

Would you mind using Code::Blocks or gcc instead? And are you trying to create a static or dynamic or shared library?

Tellalca 19 Posting Whiz in Training

Why won't you use allegro's timers ?

Tellalca 19 Posting Whiz in Training

If you want good graphics you can grab OGRE 3D.

Tellalca 19 Posting Whiz in Training
Tellalca 19 Posting Whiz in Training

Hey;

I'm trying to change the mode of a file in Linux system.

I know I must use chmod(const char* path, mode_t mode) but I don't really know how to handle the mode. How can I manipulate mode_t variable to apply my own mode?

Tellalca 19 Posting Whiz in Training

This is not the whole assignment. What I asked is a part of the assignment. The other parts are done like multithreading. I never ask people to do my assignment.

Nevermind, if anyone else needs here is what I was looking for : http://www.gnu.org/software/libc/manual/html_node/File-System-Interface.html#File-System-Interface

Tellalca 19 Posting Whiz in Training

I'll try that. What have you used for 3D?

Tellalca 19 Posting Whiz in Training

Hey;

I have an assignment. My assignment includes the following tasks to be implemented under Linux:

– Display a list of all available files (with their types) in the working directory,
– Display a list of only regular files in the working directory,
– Display a list of only directories in the working directory,
– Run a program within the shell (shell should not terminate after execution),
– Change the current working directory,
– Display information about a given filename (size, type, etc),
– Change file mode,

• Do not use system() function.
• Use execl [/execlp/execle/execv/execvp] only in runCommand() function.

I need some info and resources. Which libraries and functions do I need to achieve this functionalities?

Tellalca 19 Posting Whiz in Training

If you want to know more about compiling, linking and programming I really advice you to use g++ ( minGW in windows ) and a simple text editor. Linux is better than Windows in this sense ofcourse if you mind using it.

Tellalca 19 Posting Whiz in Training

Pointers are not rocket science. It is actually an a variable storing the adress of the variable you are pointing.

int n = 10; // this is an ordinary variable
int *a = &n; // this sentence means a is a pointer to an integer and evaluated to the address of n

It is as simple as that. What you must really understand is why we need to use pointers.

Do a search about it. And do lot of practices like sorting, printing, editing array like data by using pointers. Passing data back and forth between functions.

Tellalca 19 Posting Whiz in Training

You can do it creating a new thread, process or simply using a callback function. I don't use windows though, to create a thread in Linux pthread_create(), to create a new process use fork().

Use function pointers to handle callbacks.

Tellalca 19 Posting Whiz in Training
Tellalca 19 Posting Whiz in Training
#
for( CountDown i = 5 ; ! i.end(); i.next())
#
std::cerr << "test\n";

CountDown::end() function checks if it has reached 0 but not returns a boolean value. You must return true if it is zero in order to use it with the for loop above.

Tellalca 19 Posting Whiz in Training

Thanks. Your way of handling is different than mine i think. Isn't handling signals more convenient way of handling zombie processes than checking zombie processes every application logic cycle?

It may not be so overwhelming but if you think ideally would not it waste some CPU power too?

Tellalca 19 Posting Whiz in Training

Need help please. This one is important for me.

Tellalca 19 Posting Whiz in Training

Hey;

I am trying to handle the SIGCHLD and therefore prevent zombie processes walking around .)

The program does not work the way it should however. I am counting how many times the ZombieHandler is called and at the end of the program it says zero. What might be causing the error?

#include <iostream>
#include <cstring>


#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <wait.h>

sig_atomic_t total = 0; // number of calls to ZombieHandler

void ZombieHandler(int signal_num) // wait for the child process and clean up
{
    int status;
    wait(&status);
    total++;
}

int main(int argc, char** args)
{
    struct sigaction sa;
    memset(&sa, 0, sizeof sa);
    sa.sa_handler = &ZombieHandler;
    sigaction(SIGCHLD, &sa, NULL);  // set sa as sigaction when SIGCHLD signal occurs

    pid_t child;
    child = fork();
    if(child == 0) // child process
    {
        std::cout << "Child: My PID is " << getpid() << std::endl;
        std::cout << "Child: My parent PID is " << getppid() << std::endl;
        pid_t grandChild = fork();
        if(grandChild == 0) // grand child process
        {
            std::cout << "GrandChild: My PID is " << getpid() << std::endl;
            std::cout << "GrandChild: My Parent PID is " << getppid() << std::endl;

            return 0;
        }
        else
        {
            return 0;
        }
    }
    else // parent process
    {
        std::cout << "Parent: Number of calls to ZombieHandler is " << total << std::endl;
        return 0;
    }
}
Tellalca 19 Posting Whiz in Training

Yes, show method made it visible. Thanks!

Tellalca 19 Posting Whiz in Training

Hey;

I am following CoreJava and came to Event Handling chapter. I am trying to show a popup menu when the red button is clicked, but not works. Background color changes but no popup menu is shown. What is the problem?

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package corejava_eventhandling;

import java.awt.EventQueue;
import javax.swing.JFrame;

/**
 *
 * @author melt
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                Frame frame = new Frame();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);
            }
        }

                );
    }

}
package corejava_eventhandling;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Frame extends JFrame
{
    private static final int DEFAULT_WIDTH = 300;
    private static final int DEFAULT_HEIGHT = 200;
    private JPanel panel;
    public Frame()
    {
        setTitle("Button Test");
        setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

        JButton yellowButton    = new JButton("Yellow");
        JButton blueButton      = new JButton("Blue");
        JButton redButton       = new JButton("Red");

        panel = new JPanel();

        panel.add(yellowButton);
        panel.add(blueButton);
        panel.add(redButton);

        add(panel);

        ColorAction yellowAction    = new ColorAction(Color.YELLOW);
        ColorAction blueAction      = new ColorAction(Color.BLUE);
        ColorAction redAction       = new ColorAction(Color.RED);
        Panic panicAction           = new Panic();
        yellowButton.addActionListener(yellowAction);
        blueButton.addActionListener(blueAction);
        redButton.addActionListener(redAction);
        redButton.addActionListener(panicAction);

    }

    private class Panic implements ActionListener
    {
        private String message = "Warning ! Nuclear Missile Launched!!!";

        public void actionPerformed(ActionEvent event)
        {
            
            PopupMenu pop = new PopupMenu(message);
            Frame.this.panel.add(pop);
            panel.setVisible(true);
            
            
        }
    }
    private class ColorAction implements ActionListener
    {
        private Color backgroundColor;
        public ColorAction(Color c)
        {
            backgroundColor = c;
        }

        public void actionPerformed(ActionEvent event)
        { …
Tellalca 19 Posting Whiz in Training

maybe the problem was with your router.internet does not effect your LAN i think.

Tellalca 19 Posting Whiz in Training

Hey;

I am wondering if there is a way of tracking ftp packets of a webserver ? This webserver is not a part of my LAN. If so, how does it work ?

I can keep track of my own LAN traffic but how about seperate networks maybe behind a NAT?

Tellalca 19 Posting Whiz in Training

Go and learn about some socket programming and fstream.

sergent commented: Thats not really useful comment! -1
Tellalca 19 Posting Whiz in Training

Simply call by reference creates a reference to the object and passes that. Think of reference is another name for the object. You can manipulate the data and do not copy the whole object to pass it to the function.

By passing it by a pointer you just pass its adress. You can use and increment decrement this adress to move around the actual object. You still do not copy the object but you have a greater flexibility to manipulate the adress and data both.

Tellalca 19 Posting Whiz in Training

Hey;

I am currently busy with multiprocessing and multithreading. There I saw a signal SIGCHLD which is an excellent zombie process cleaner by handling that signal.

But when we are writing our handler function why we declaring it with an signal number arguement ? Is this arguement is automatically passed by sigaction() function ? Here below is the code

void ZombieHandler(int signal_num) // why is signal_num needed? Is it passed implicitly by sigaction() function ?
{
	int status;
	wait(&status);	// clean up the ended process and save the status
	child_exit_status = status;
}
int main(int argc, char** args)
{
	struct sigaction sigchild_action;
	memset(&sigchild_action, 0, sizeof sigchild_action);
	sigchild_action.sa_handler = &ZombieHandler;
	sigaction(SIGCHLD, &sa, NULL);

	/*Do things, create child processes
	// and they will be handled securely*/
	return 0;
}

Thanks!

Tellalca 19 Posting Whiz in Training

C++ works on xbox, pc, playstation, android and most of the embedded systems. Go for it but it will be hardcore.

Tellalca 19 Posting Whiz in Training

Google may not be so random, try facebook :) Yes the HTTP protocol uses port 80.

Tellalca 19 Posting Whiz in Training

I don't know if that works but you may want to pause and see the result.

Tellalca 19 Posting Whiz in Training

I started game developing by creating console based text games.

They are very good to teach you about OOP, game loops and logic, handling inputs and outputs.

If you can do just one or two console games you can make your way to SDL or SFML( an object oriented and better suit C++ library ) easier.

I think http://lazyfoo.net/articles/index.php is the ultimate source you need to start developing games about SDL.

For compiler I would use Visual Studio or g++(GNU C++ compiler). CodeBlock is good too.

Tellalca 19 Posting Whiz in Training

Ok, I was thinking about what you told too, I wanted to know if there is a more convenient way to do that. So that is how all java programmers do or should do ?

Tellalca 19 Posting Whiz in Training

Hey;

I'm trying to do a hang man game in Java. I newly learned some stuff about programming some GUI using Swing and AWT, but I'm not still clear with it.

The problem is that all the drawing is done by a single function paintComponent() from the JPanel that I should add to the JFrame. The function does not give me flexibility to take some parameters, there is only one parameter, Graphics object.

I want to be able to respond to the users answer/input to the program and draw some primitive shapes such as lines and circles. But I have only one function, and that does not let me pass parameters to it.

I know I got something wrong there but I cant make my way out. So can you tell me what I got wrong and a code snippet to show me that draws a line if user inputs a "line" in a text box and a circle if the user inputs a "circle".

class MyPanel extends JPanel
    {

    @Override
    public void paintComponent(Graphics g)//This function always does the same, no interaction with user inputs
    {
        Graphics2D graph = (Graphics2D)g;
        graph.draw(new Ellipse2D.Double(100, 100, 200, 300));
        
        graph.drawString("Heeeyy!!!", 100, 400);
        Rectangle2D rec = new Rectangle2D.Double(100, 100, 50, 50);
        graph.draw(rec);

        Line2D line = new Line2D.Double(new Point2D.Double(0,0), new Point2D.Double(300, 400));
        graph.draw(line);
        graph.setPaint(Color.MAGENTA);
        graph.fill(rec);
    }
}
Tellalca 19 Posting Whiz in Training
public Vec(int length)
    {
      double[] v= new double[length];
      for(int i=0;i<length;i++)
      {
          v[i] = 0.0;}
 
    }

in the for loop you must use "v.length()" or "length - 1" since arras start with 0, a 10 element arrays last element's index is 9.

Tellalca 19 Posting Whiz in Training

Use the CODE-tags

Tellalca 19 Posting Whiz in Training

You can try google. There are a lot of sources about allegro, c++, game development... If you are stuck then you should ask here.

http://www.gamedev.net/ go here and read the forums

Tellalca 19 Posting Whiz in Training

If you are going to do it in XNA you'd better learn C#. Visual Basic and Visual C++ will do too ofcourse.

Tellalca 19 Posting Whiz in Training

Thank you all. Yes that was what I wondering. I see there is no flexible and easy way.

Tellalca 19 Posting Whiz in Training

I don't think you should look for a network book special for game development. You can use any good network book to learn basic and then do some socket programming.

I don't have much experience in network programming but that is how I will do this summer.

There is a good socket programming book free online which is referenced by many academic staff too : http://beej.us/guide/bgnet/

nssltd commented: I Agree +3
Tellalca 19 Posting Whiz in Training

Thanks for replies. I'm actually looking for a way to protect my data from the "dangerous methods".

In C++ if you don't want a function to change your original data's state, you can pass it by call by value or to omit the overhead of copying you can pass it as "const" pointer or reference. So if the function tries to change your original data( not the parameter ) the compilation fails.

This way you put a layer of security and obey the OOP principles. In Java is it possible to force a permission check like this during compilation?

I hope I'm clear with that.

Tellalca 19 Posting Whiz in Training

Hey;

I'm getting into Java. I'm coming from C++ base and I wonder how can we use "const" parameters in Java?

For example if I don't want the function to be able to change the value of a parameter, what do I do?

void modify(RefObject parameter)
{
parameter.set(new RefObject); //should cause compiler error
}
Tellalca 19 Posting Whiz in Training

Cool especially when more components come in to play.

Tellalca 19 Posting Whiz in Training

Hmmm, I wonder ...
So if I have a textfile consisting of 26 characters, the alphabet for example, I could reduce its size by 97% of 26, being 25.22???
So I could zip all the information of the alphabet in less than 1 char?

It says "nearly upto". So it does not have to compress all files %97, it may and it may not.

Tellalca 19 Posting Whiz in Training

Wow! The problem was with the text editor. It did not compile the latest version of the code. I like Linux but when it comes to IDE Visual Studio absolutely rules. Is it too hard to create a good and responsive IDE???

Tellalca 19 Posting Whiz in Training

You can't erase some data from the file. You must copy the updated data(text in this case) to a new file. You can get the data to the memory then close the file then open the same file with "write" attribute. This deletes all the data in the file. Then flush the updated data to the file. Then you are done.