gusano79 247 Posting Shark

I'm not sure exactly what you're asking, either, but here's a thought: Most developers I've met want to produce the highest quality software possible, but in practice, the level of software quality for a given project will depend on the risks involved and the cost of failure.

Consider the specific quality problem of an application that occasionally crashes for no immediately apparent reason. If this application is, for example, a simple image viewer, the worst thing that can happen is the user has to take a minute or two to restart the viewer. On the other hand, if the application is an embedded control system for a NASA space probe, a software crash could send it flying into the sun instead of into orbit around Mercury.

Of course, you'd want to fix the crashing problem in both cases. If the image viewer project was on a tight schedule, though, it is plausible that it could ship with the bug (Microsoft and Adobe products come to mind)--but you can bet your ass the space probe launch would be delayed until they fixed it.

gusano79 247 Posting Shark

Oh my. That's one ridiculous infomercial website.

What do you think it was coded in?

If you take the time to read the page, it's right there in the middle of his sales pitch: "...all the software I develop is created using Adobe Flash."

And how long do you think it would take to make something similar to it?

IMO, it wouldn't take very long. The application is neither large nor complex. Mr. Ken Reno is claiming 5 days from concept to version 1.0, and another 19 to get from there to 2.0, and I don't get the impression that he's any kind of lightning-fast software genius. A couple of weeks should be plenty of time, even for a lone developer. I would also expect most of that time would be spent on design and requirements-like activities--actual coding would be very quick.

PythonNewbie2 commented: Great answer! Everything I asked was answered! +1
gusano79 247 Posting Shark
String hexString = "0x5C";
Byte myNewByte;

myNewByte = Byte.Parse(hexString);

Error: "The input string was not in a correct format"

Byte.Parse() with just a string parameter doesn't know that "0x" means hexadecimal. What you need is the overload of Byte.Parse() that lets you tell it to look for hex. You'll need to give it NumberStyles.AllowHexSpecifier or NumberStyles.HexNumber, and you can't use the "0x" at the front either... you'll need to strip that out first.

Something like this:

String hexString = "0x5C";
Byte myNewByte;

myNewByte = Byte.Parse(hexString.Replace("0x", ""), NumberStyles.HexNumber);
gusano79 247 Posting Shark

But "make" command in unknown in my command prompt.I have MinGW installed which comes with codeblocks.

My Code::Blocks distribution came with "mingw32-make.exe"; check your C::B installation folder to see what came with it, e.g., C:\Program Files\CodeBlocks\MinGW\bin .

gusano79 247 Posting Shark

Umm, does the trick work at basic C? I'm not sure since we've only been taught of Basic C at the moment. so far, with loops.

Oh, and at <stdio.h>.

You can do this in C. Don't focus too much on the technology; the question is about a mathematical algorithm, and the answer will be the same no matter what language you use to implement it.

gusano79 247 Posting Shark

Hi, i have tried this, but can not get it to work.
From what im reading, doesn't clock() and timerStart have the same value? so it will not start?

Read about clock() . It's not really a "timer"--all it does is tell you what the time is when you call it. In order to find out how much time has passed, you have to call clock() again, and compare the two values.

From my (admittedly not super-clear) example:

clock_t timerStart = clock();

This happens right before the main loop. It tells us what time it was when the loop started.

Then, in the loop:

// Track only the number of seconds since timerStart
seconds = (clock() - timerStart) / CLOCKS_PER_SEC;

...figures out how many seconds since the loop started.

The call to clock() here happens every time through the loop, so it's possible that for the first time--or more, depending on how fast the loop is--it might return the same as the initial call to clock() . Eventually, though, enough time will pass and we're looking at the time elapsed since we assigned timerStart originally.

Then, when it's time to start counting again:

// Reset clock() here--actually, just track a new start time
timerStart = clock();

..reassigns timerStart , so we're measuring from the moment clock() gets called for the assignment--this effectively resets the timer.

So we've built a simple timer from a "what time is it?" library function. …

gusano79 247 Posting Shark

Here's a timer class of mine that's put together a little differently. On Win32 platforms, it uses the Windows high-resolution timer if it's available, or clock() if it's not. On non-Win32 platforms, it compiles to use gettimeofday() .

Also of possible interest: clock vs gettimeofday

gusano79 247 Posting Shark

Make a simple timer class to simplify stuff. For example :

Beat me to it! =)

This is better; the timer details don't distract from your main loop.

gusano79 247 Posting Shark

the clock starts when the program is run and after 8 secs, FIVE moves position.
When i press F, i want FIVE to reset its position [which it does], and to reset the clock(), so that after 8 secs, FIVE will move again.
Anyway to do this?
Using Windows 7, visual studio.

Short answer is you can't reset clock() . It always returns the ticks elapsed since the program started.

What you can do is keep around some sort of "seconds since last time FIVE moved" variable, and reset it to the current number of ticks when you want to reset the clock. It might look like this:

int seconds;
clock_t clock();

// This keeps track of the start time for your 8-second timer
clock_t timerStart = clock();

// I added this to keep track of whether or not we're using the 8-second timer.
// This way, we can stop the timer when it triggers
bool timerOn = true;

while(true) // I'm assuming your code has this in a loop somewhere...
{
  // Only check the timer if it's "on"
  if(timerOn)
  {
    // Track only the number of seconds since timerStart
    seconds = (clock() - timerStart) / CLOCKS_PER_SEC;
		
    // Changed "==" to ">=" here; this catches instances where one check ends up
    // at 7 seconds, but the loop takes so long that the next one reads 9 seconds
    if (seconds >= 8)
    {
      FIVE.SetPositionX(-1);

      // Turning off the timer here; we …
gusano79 247 Posting Shark

I am trying to loop until length is meet but it only creates one char and I am trying to when it gets to certain char to skip and do nothing but loop until length is meet.

char symbol,symbols; 
string password;
for(int d=0; d < numericUpDown1->Value;++d) 
{
    symbol = rand() % 92 + 33; 
    /* ... */
    symbols = symbols + symbol ;
}
password = password + symbols;

Shouldn't symbols be a string ?

It looks like you want to concatentate stuff to it, but as written, the + operator changes its value instead, leaving it as a single character.

gusano79 247 Posting Shark

int a; counts as a tentative declaration in C. If you don't write in a default value, you can declare the variable again later. Try providing a value both times you declare it and you should get an error:

#include <stdio.h>

int a = 42;
int a = 42;

int main()
{
  a = 100;

  printf("fdfsa");
  scanf(&a);
}

You get the error in C++ because C++ doesn't have tentative declarations.

Also: Best practice in C is to only declare variables once. Otherwise, things can get funky really fast, especially if you have multiple declarations in different files... yuck.

gusano79 247 Posting Shark

@gusano79
Thanks for u r reply..
Correct me if I am wrong.. but are'nt SqlLite and MySQL Relational databases and not Object oriented databases ?

Yes, sorry! I'll read more carefully next time. :S

gusano79 247 Posting Shark
gusano79 247 Posting Shark

The project will basically need to track changes that occur within a string so they can be highlighted.

It looks like you need some kind of diff feature for your project.

This is a well-understood problem, and you should be able to find an implementation that meets your needs. One example is the Diff.NET, which includes a library called "MeneesDiffUtils" that may work well for you.

Ideally the application would spot that change in the string and prehaps inside a new word at the index of the change, say '<span class="Change">' and then the closing tag at the end of the change.

A diff library will tell you where all of the changes are, but you're on your own for deciding what to do with them. If you expect to be performing lots of string operations, I recommend you use a StringBuilder.

gusano79 247 Posting Shark
string host = this.HostAddress.Text.Replace(@"\", @"\\");

Immediate reports host as:
"C:\\\\Program Files (x86)"
When it should report it as:
"C:\\Program Files (x86)"
the original text was:
"C:\Program Files (x86)"

Any thoughts?

Your call to Replace is correct, as you can demonstrate by running the following tests (the third one is supposed to be incorrect):

using System;

class Program
{
    public static void Main(string[] args)
    {
        // No @, double \
        WriteReplacement("C:\\Program Files (x86)");
        
        // With @, single \
        WriteReplacement(@"C:\Program Files (x86)");

        // With @, double \
        WriteReplacement(@"C:\\Program Files (x86)");
        
        Console.ReadKey(true);
    }
    
    private static void WriteReplacement(string text)
    {
        Console.WriteLine(
            "\"{0}\" --> \"{1}\"",
            text,
            text.Replace(@"\", @"\\"));
    }
}

...so I imagine there's something going on with the text in HostAddress .

I have to ask, though--why do you need to escape the slash in the first place? You only have to escape them when you're writing string literals in code. If you're getting typed input from the user, HostAddress.Text will be the correct path string, and doubling them up will confuse the standard IO classes.

gusano79 247 Posting Shark

I am currently running on windows and have and issue when i try to read/write files,the problem being that it just doesn't happen.

That doesn't give us very much to work with; it would help if you could clarify what "just doesn't happen" means. Is it truly not happening, as in the code appears to work but no files show up, or is it something else? Please post some details about exactly what is happening, including a short example of the code that's failing to work correctly.

gusano79 247 Posting Shark

If you're only adding .1 or .25 etc, but the result shows up as something which isn't a multiple of .1 or .25, then y was clearly not equal to a multiple of .1 or .25 to begin with. In other words your initial y value must have been something weird; how was y initially set?

More likely it's due to floating point representation, in particular: The decimal value 0.1 has an infinite binary expansion, so it's impossible to represent accurately in a floating-point number.

gusano79 247 Posting Shark

whats going on?

Read about floating point accuracy.

how to get rid of this fuzyness particularly in cases where i know i'm just adding .1.

You might try sticking with integers and using fixed-point math... with the example you posted, you could use a scaling factor of 100: y would actually equal 53900, add 10 instead of 0.1, add 25 instead of 0.25. You'd just have to remember to divide by 100 when printing values.

gusano79 247 Posting Shark

This is the algorithm I am working on, however, I believe it is not working properly because it chooses points that are very close to each other to be centers:

If anyone can offer any insight on this, I would greatly appreciate it. The algorithm seems to only be selecting points far away from the first center (which is chosen randomly outside of the above loop.)

The pseudocode looks okay; I've attached a quick little .NET console program that appears to confirm your approach. This suggests to me that there might be some errors in your implementation of that algorithm. If you post actual code, we could have a look at it.

I am trying to write a clustering algorithm where, given location of certain points (I.e, latitude and longitude) I need to choose 50 of these to be cluster centers such that the diameter of each cluster is minimized. To that end, I believe that the program should choose the next center to be the point that is farthest away from all the previous centers.

Questions:

  • Are you assigning non-center points to the cluster with the nearest center?
  • Are you limited to choosing existing points as cluster centers, or can you use any lat./long. coordinate for a center?
  • Does "diameter" mean the distance from a cluster's center to the farthest point in each cluster?

It sounds like an iterative approach--something like Lloyd's algorithm--might be appropriate:

  1. Pick an initial set of centers (randomly, …
Agni commented: like the spirit :) ... +2
gusano79 247 Posting Shark

Hi,

I am implementing a project where I have to use adaptive thresholding on an image. That is, the threshold value must not be global, but must adapt itself with the image. I have thought a lot, but am unable to get a logic. It would be really helpful if someone can help me with the code, or atleast the logic

Here's a link to get you started. Google is your friend. =)

gusano79 247 Posting Shark

Whenever I create a new database from a C# program and create tables for that database, the tables always show up under the creator's default database instead of being listed under the newly created database.

Hi again!

If you're using the same connection string that created the database to send the create table commands, remember there's no database specified on that connection. Once you've created the database, you'll have to create a new connection that specifies the new database's name. Use that connection to create the tables.

If that doesn't apply to what you're doing (i.e., you're already creating a new connection) or it doesn't solve the problem, please post the relevant code so we can help.

gusano79 247 Posting Shark

I am still unable to Open. I went into SQL Server Management Studio Express and granted all privileges to the root user but still no luck.

A more detailed description of the problem than "still no luck" would help... is it the same exception or a different one? Exception message and stack trace are both useful. Also, what version MySQL are you connecting to, and with what .NET data library?

gusano79 247 Posting Shark

My code structure to create a new Access database is in this order:

1. Create the database
2. Open the database
3. Create a database table

Is this the same order that I should apply for creating a mySQL database?

It's not quite the same; Access is a file-based database system, where MySQL is server-based, so you'll need some sort of open connection to the server to do anything useful.

When the program attempts to run the ExecuteNonQuery command for CREATE DATABASE, it fails because it requires an open database connection (ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.)

I don't have a server handy to test this on, and I'm not sure what MySQL library you're using (ODBC, Connector/Net?)... but I think it would look something like this:

MySqlConnection connection = new MySqlConnection("Data Source=serverName;UserId=rootOrOtherAdminAccount;PWD=topSecretPassword;");
MySqlCommand command = new MySqlCommand("CREATE DATABASE FancyDatabase;", connection);
connection.Open();
command.ExecuteNonQuery();
connection.Close();

Is that different than what your code is doing?

gusano79 247 Posting Shark

AFAIK Normal Windows development (e.g. what you get with normal Visual Studio installations) does not handle multiple key presses, not including modifier keys (ctrl, alt, and shift.)

To clarify, the .NET Framework doesn't provide automatic handling of multiple key presses. You can still handle them yourself.

The problem is Windows supports two types of key press events: KeyDown/Up and Repeat. Key up and down is great, but if you hold a key down, it fires Repeat until that key is let go. Not handy if you are trying to hold 2 keys down at once.

This is what's keeping your code from working right--when you hold one key down and press another at the same time, you stop getting repeats from the first key, and start getting them from the second.

As long as your game logic is coupled to keyboard event handling, you'll always need a new key event to do something in game logic. Because you never get repeats for more than one key at a time, you won't be able to do two actions at once.

The solution? Decouple keyboard event handling from game logic.

First, you need a place to keep track of which keys are currently down. If you only have a few keys you're interested in, you might have a couple of lines like this:

private bool spaceKeyDown = false;

Then, handle the "key down" event:

private void MainFormKeyDown(object sender, KeyEventArgs e)
{
    if(e.KeyCode == Keys.Space)
    {
        spaceKeyDown …
gusano79 247 Posting Shark

hi...i'm making a game that uses the direction arrows and fires with space...the problem is that when i keep holding 2 keys it makes only the behavior of one....can any1 tell me what i shall do

Could you post the code you're using to track key up/down status? That would help us find what's going wrong.

gusano79 247 Posting Shark

...I found that a word (dw) will only hold the last thing passed to it. You can type "abcdefg", but the word will only hold the value "g"...

Right. store will always refer to the same memory location, so every time you write to it, whatever value was there is overwritten by the new value.

...What I'm trying to ask is, would there be a way to make it store everything typed, like.. create a string out of a series of characters?

As long as store only points at a single location, no.

What you want is a series of storage locations, with store pointing at the start... instead of dw 0 , do something like times 100 dw 0 . Then all you need is another variable to hold the address in which to store the next input character. Start it out pointing at store , and every time you read a character, load it into the location at the address of store plus the value of the variable, then increment the variable. That way all of the input characters are saved at different locations, and you have all of them.

Additional thoughts:

You don't have infinite space to keep recording characters, so you'll have to decide how much space to reserve and what happens if someone types more characters before they hit the carriage return.

Instead of defining store as a series of 0 bytes, try filling it with '$' --that way, no …

gusano79 247 Posting Shark

You can't link directly to a COM library; you have to link to a .NET interop library. The VS IDE secretly generates this library for you when you add a COM project reference. Since you're using the command line, you'll have to generate it yourself. Use tlbimp.exe; it comes with the SDK.

bondo commented: Exactly what I needed +2
gusano79 247 Posting Shark

From what I've heard, programs are considered AI when they can fool a human being into thinking they are human (ie. over IRC chat or similar). ...

It's called the Turing test, after Alan Turing.

Here's an article that may be of interest... I'll throw in a quote from the article (italics mine): Turing intended his test specifically as a measure of human intelligence. An entity passing the Turing test may be said to be intelligent, and moreover, to possess a human-form of intelligence. Turing specifically states that the converse statement does not hold, that failure to pass the test does not indicate a lack of intelligence.

Much depends on how you decide to define "intelligence" and how exactly you go about measuring it.

Further reading:
http://tekhnema.free.fr/3Lasseguearticle.htm
http://www.pcmag.com/article2/0,4149,1200185,00.asp
http://www.google.com/search?hl=en&ie=UTF-8&q=Turing+test :)

... Several programs have been able to do this sucessfully.

Such as? Who wrote them? When? That's a pretty bold statement, and these "several programs" would have received quite a lot of attention, which I haven't noticed at all. And don't say ELIZA.

I'm of the opinion that if the person asking the questions is clever enough, he/she will be able to trip any program written to date into revealing itself as not a human being. I won't say that it'll never happen, but we're far from creating anything that will really pass that particular test.

--sg