deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Actually some of my friends often say me that pointer is hard , too hard(however i've not started learning pointers , so i can't say).

I strongly believe that the majority of what makes pointers "hard" is people hyping them as such. The concept is very simple, and the syntax is equally simple. You can get lost in a mess of indirection, but that's more a matter of design than pointers being "hard". You can just as easily make a mess of if..else statements, yet those aren't hyped as being unusually difficult to grasp and use.

so please recommend some good books particularly targeted to Pointers

I'm not aware of any at all, much less any good ones. There are tutorials online though. I think this one is a good intro, but I'm a bit biased.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I had one once with a knowledgeable programmer and some time later, he ceased to connect. I think he had too strong convictions and he wanted everybody to agree.

How much time is "some time"? Maybe he just left for other perfectly legitimate reasons. Even if your assumption about his motivation are accurate, it's impossible to avoid offending everyone. I'd much rather see civil airing of grievances and productive discussion than let things silently stew.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Separating the check for end-of-file from the actual read is risky, and you're encountering a very common beginner's problem with it: the last line gets processed twice. This is because the eof member function won't tell you that the next input request will hit end-of-file, only whether the previous one did. Since you unconditionally process what was read (or not read in this case) after reading from the file, the last line gets processed twice.

Since the >> operator returns a reference to your stream and the stream object has a boolean conversion for the stream's state, you can do it right with less code:

while(in_file>>eve>>am>>dat>>bal)   
{
    cout<<eve<<setw(10)<<am<<setw(20)<<dat<<setw(10)<<bal<<endl; 
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

if the current working directory (.) is not before the directory holding "notepad.exe" in your PATH environment, then it will not work as you specify

True, but it's merely one example. As long as the attacker can figure out where to place the malicious program, the hole exists.

This is why it is much more preferable to use full paths

Even if you use a full path, the problem still remains unless you can guarantee that the executable cannot be compromised.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This will be a relatively quick article because it's a simple issue. The system function gets a lot of flak for being slow because it calls the shell runtime to execute a command, but I rarely see the more devastating issue of security brought up.

system is insecure in many cases. Let's use a simple example of opening Notepad on Windows:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    system("notepad.exe");
    getchar();
    return 0;
}

This works like a champ, so what's the problem? What if I told you that subverting this program is as simple as copying a malicious program into the same directory and calling it notepad.exe?

#include <stdio.h>

int main(void)
{
    puts("Malicious code! Arrrgh...");
    return 0;
}

Now instead of that lovely Notepad interface, you're met with a dastardly console message that your code has been hacked! Worse, the malicious code could do its evil and then open Notepad, with you none the wiser that bad stuff went down in between. If your program is run with superuser privileges, then the malicious program also has those privileges and can do a lot of damage.

Exercises
  1. Try it for yourself and see what happens.
  2. Does this work for built in commands like "cls"?
  3. Can you find a safe way to execute an external program?
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

if you could solve this program please i really need it today .

Welcome to reality. Many of us have worked with someone who cheated their way to a job and couldn't perform. It's not a good situation for a team, so you'll probably get no sympathy.

Next time work harder and start sooner, because you can't expect someone to bail you out if you can't meet a deadline.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This thread is clearly inflammatory, but I'm letting it slide because there's potential for good discussion iff everyone remains civil. Please keep that in mind, thanks.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How much is too much?

If we don't destroy society in the near future, I can see this question becoming more and more relevant. Barring prosthetics, it's easy to imagine technological enhancements for memory, vision, general health and wellness, strength, stamina, and survivability in harsh environments. Full dive virtual reality would also require a certain measure of invasive interfacing with the body.

How much is too much will depend greatly on ideological views, and also a consensus on when a human is no longer a human. It's doubtful there will ever be any kind of agreement, which practically guarantees strife (if not all out violence) from the different camps.

We can already see what will happen from current experience with genetic research and possibilities therein.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are we slowly turning ourselves in robots?

You've asked this question with the implied assumption that the result is bad, which hasn't been convincingly argued. What's inherently wrong with being partially "robotic"? Until we have a basepoint for discussing the ramifications intelligently, we need to move away from irrational fears.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Loop through the value and find the largest possible numeral that will fit. Then print the numeral and decrement the value. For example:

while (value > 0) {
    if (value >= 1000) {
        // M
    }
    else if (value >= 500) {
        // D
    }
    else if (value >= 100) {
        // C
    }
    ...
}

This approach isn't well suited to a switch statement as a switch is basically a table lookup with exact values and you really care about the range. But you can voodoo something workable with a little creativity. A start might be to extract your keys based on the value, then check them:

while (value > 0) {
    const keys[] = {1000, 500, 100, 50, 10, 5, 1};
    int i;

    for (i = 0; i < sizeof keys / sizeof *keys; i++) {
        if (value >= keys[i]) {
            break;
        }
    }

    switch (keys[i])
    {
        case 1000:
            // M
            break;
        case 500:
            // D
            break;
        case 100:
            // C
            break;
        ...
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

18 compiler errors

Unhelpful. If you're getting compiler errors, post the errors in detail and the code that the errors refer to. Otherwise you have no reason at all to expect anyone to be able to assist you in fixing them.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

can anyone make a code for this problem.?

Yes, yes we can. But we won't because that defeats the purpose of the exercise which is for you to learn how to do it. If you have problems with your code, feel free to ask, but don't ask someone to write all of the code for you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

can you explain your code a bit, so that i can understand it ....

It's pretty straightforward, the month value is passed around using properties rather than having one form look at another form's controls or private variables. Is there any specific part you don't understand that I can explain in more detail?

as to NumericUpDown, it does not like decimal,double.

NumericUpDown can be configured for floating point precision with the DecimalPlaces property. The Value property evalutes to a decimal, which can be cast to double if need be.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Let's get one thing clear first, are you using a hardware barcode scanner or do you need to recognize barcodes on an image that's stored on the file system? The two are different beasts, and the former will typically be easier because a hardware scanner will just give you a string on standard input whereas recognition from an image requires a certain measure of library support.

Also, what kind of barcode are we talking about? 1D, 2D?

Begginnerdev commented: For his/her sake I hope it's just textbox and query. :D +9
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What issue are you having?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My bad, it should have been if (parts.Length != 2). If code you find online is broken, don't be afraid to troubleshoot it yourself. We're all fallible, after all. ;)

i don't know where can I put this code on my form. sorry im newbie on this.

You'd pull the ID directly from the database, then call AutoIncrement to get a new ID for new records is what I was thinking. Or maintain the most recent ID in your code and update it as necessary for new records For example:

private string _connectionString = "<your connection string>";
private string _lastId = "AN-00000000"; // Default first ID if there are no records

/// <summary>
/// Retrieves the most recent ID from the database.
/// </summary>
private void Form1_Load(object sender, EventArgs e)
{
    using (var connection = new SqlConnection(_connectionString))
    {
        connection.Open();

        using (var cmd = new SqlCommand(connection))
        {
            cmd.SelectCommand = 
                "select top 1 piId" + 
                "from tblpair_individual_membership" +
                "order by piId desc";

            var id = cmd.ExecuteScalar();

            if (id != null)
            {
                _lastId = Convert.ToString(id);
            }
        }
    }
}

/// <summary>
/// Adds a new client to the database
/// <summary>
private void buttonNewClient_Click(object sender, EventArgs e)
{
    var newId = AutoIncrement(_lastId);

    using (var connection = new SqlConnection(_connectionString))
    {
        connection.Open();

        using (var cmd = new SqlCommand(connection))
        {
            cmd.InsertCommand = "insert into tblpair_individual_membership (piId) values (@piId)";
            cmd.Parameters.Add("@piId", SqlDbType.VarChar).Value = newId;

            if (cmd.ExecuteNonQuery() == 1)
            {
                // Only update the last ID on a successful insert
                _lastId = newId;
            }
        }
    } …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Simple: don't do that. To store arbitrary binary files in a table you'd need to use blobs, and I can tell you from experience to avoid blobs where possible.

A better approach is to store the files on the file system, then store the path to them in your table. Then the blob becomes just a varchar(255). From the database perspective it's much easier to work with.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i is uninitialized in your snippets. Further, you still need to dereference in this case because operator>> is expecting a reference to the object rather than a pointer to it:

#include <algorithm>
#include <iostream>
#include <iterator>

using namespace std;

int main()
{
    int a[] = {1, 2, 3, 4, 5};
    int i = 2;

    cin >> *(a + i);

    copy(a, a + 5, ostream_iterator<int>(cout, " "));
    cout << '\n';
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Exactly the same way. A 2D array "decays" to a pointer to an array, so the pointer notation is just an extension of how you do it with a 1D array:

// a[i][j]
*(*(a + i) + j)

Or equivalently:

*(a[i] + j)

Or in the opposite direction:

(*(a + i))[j]

The equivalence means these notations are interchangeable and mixable if you get your parens right.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

And that represents a valid path, how?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yup. You need to split the string to extract the number part, convert it to int, add to it, then paste the string back together:

private static string AutoIncrement(string id)
{
    var parts = id.Split('-');

    if (parts != 2)
    {
        // Expected format "XX-dddddddd"
        throw new ArgumentException("Invalid id format");
    }

    int seq;

    if (!int.TryParse(parts[1], out seq))
    {
        throw new ArgumentException("Sequence number must be numeric");
    }

    // Validate the first part if you want

    // Put it all back together into a new ID
    parts[1] = (seq + 1).ToString("00000000");

    return string.Join("-", parts);
}

The conversion to int is the important part because the + operator for string performs concatenation rather than integer addition.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

ASP.NET? WPF? Old school WinForms? What technology are you working with, because there are subtle (and sometimes not so subtle) differences between controls with the same name.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Improve it how? Make it shorter? Make it faster? Make it more intuitive? You need a specific goal, and "improve it" is not specific at all.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Did you change the to this?

string picLoc = null;
string picLoc1 = null;
string picloc2 = null;
string picloc3 = null;

Because that's not any better. If you're opening files, those strings need to have the path to the file. The framework has no idea what file you're trying to open if you don't. For example:

string picLoc = Path.Combine(rootFolder, "myimage.tif");
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Well, unless you're changing those values, it's pretty obvious why you're getting an empty path exception. Blank strings are not valid paths.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How are you generating picloc, picloc1, picloc2, and picloc3?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

However, how come it was possible to use such C++ instructions such as ofstream file; and such in a windows form application?

Because C++/CLI would be far less useful and attractive if you were denied any of the standard C++ libraries in managed code.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

why both are same ?

The array index operator is syntactic sugar for an offset from a pointer. The pointer is the base address of the array, so a[0] is equivalent to *(a + 0). Because addition is commutative, you can also say *(0 + a), which falls through to the index operator and becomes 0[a].

Note, however, that while this is possible, it's extremely poor practice. Knowing about this bit of trivia is fine for impressing people at parties, but shouldn't be used in any real code.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Now, I have a question to create a auto number like this "AN-0000-0000", it is possible to query this on C#?.

That looks fairly custom. What does each part represent and how does it change as new values are generated?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please post your code. The exception is clear about what the issue is, so you need to look into why the path you're trying to save is interpreted as being empty. Most likely it's getting cleared somewhere.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is a hard 5 digit sequence required? If all you need is something that's larger than the previous ID and smaller than the next, you can use the custom date time formatting to get a high enough resolution that practically guarantees uniqueness:

' Timestamp down to the millisecond
Id = DateTime.Now.ToString("yyMMddHHmmssFFF")
Begginnerdev commented: Can be shorthanded by calling Now() +9
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm not a fan of tight coupling between forms such that you access internals of other forms directly. My preferred method is to communicate data with either constructor parameters, properties, or events. For example (unnecessary stuff omitted):

Public Class Form1
    Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
        Using dlg As New Form2
            ' Form2 handles all of its own UI stuff
            If dlg.ShowDialog() = DialogResult.OK Then
                ' Loose coupling, use the public interface without caring about internals
                Textbox1.Text = dlg.Month.ToString()
            End If
        End Using
    End Sub
End Class

Public Class Form2
    Private m_month As Decimal
    Property Month() As Decimal
        Get
            Return m_month
        End Get
    End Property
End Class

I'd also avoid using a TextBox for numeric values because then you have to worry about validation. A NumericUpDown handles all of that for you and should be preferred unless you have unusual formatting requirements.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I first used malloc to allocate some space. Then I use this if statement to fill vertices with some char values. After that I add a null character at the end so it is properly terminated like char arrays are supposed to be.

Then strlen should work. Could you post a small but complete example that exhibits the problem?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm going to go out on a limb and guess that what you want is to clear the screen when redrawing the menu. This will keep the menu in the same physical location for each iteration of the loop.

Since you're calling it "DOS" I can only assume you're using Windows, and as much as I abhore system as a security hole, the easiest way to clear the screen is:

int menu()
{
    int choose;

    system("CLS");

    do {
    ...

Don't forget to include <stdlib.h>, that's where system is declared.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

the doThis() method is in a different class

That doesn't change anything. doThis is still passed a reference to the object, and copyOfX still makes a copy of only the reference. All references still point to the same underlying object.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Update on the new series I'm still watching in reverse order of preference.

  • Yuushibu is toeing the line of being dropped, but for some reason I just haven't been able to do it. Probably because I like Fino and want to see how she develops as a character.

  • Walkure Romanze could tone town the ecchi two notches and it'd be a fine story. As it is it's good enough that I can look past the over the top fan service.

  • Yowamushi Pedal is pretty darned good. I didn't know what to expect, and so far I'm very pleasantly surprised. The story is moving slowly though, so I'm still waiting to see if it turns into Prince of Tennis with bicycles. ;) If it does, I'll drop it with great sadness.

  • Log Horizon looks to be this season's gem. Originally my thought was that it was just an SAO knockoff to cash in on SAO's popularity, but now I'm debating which of the two I like better. It's a good problem to have. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

And? What have you tried? Please note that our rules disallow posting homework questions with no proof of effort as if you wanted us do write it for you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If by "help" you mean "do it for me", then no. If you really do mean help, you've provided precisely zero information useful for helping you. Either way, the question as it stands now is guaranteed to go unanswered.

Please provide more information and show some effort.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You don't execute any commands, of course the database wouldn't be updated when nothing is done. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There were a few changes to .NET Framework

4.5 support, which in the business world is a no-go until Windows 8 is adopted (unlikely in the near future from my consulting experience) or IT departments are comfortable installing the runtime to support applications written for it (more likely, but still a bit off). Right now the most my clients are typically willing to work with is the 4.0 framework and Windows 7.

closer compliance to C++11

Not close enough for my comfort. VS 2014 should be a solid implementation of C++11 and choice features from C++14.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The simplest solution is size. size should represent the number of items added to the array, so if size is 0, there are no items and the array hasn't been "initialized".

Also include a capacity parameter so that your functions know how many items the array could potentially hold as well.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

OpenConCls.ToString() will give you a default object representation because you didn't override ToString. This won't be a string that represents a valid integer, so Convert.ToInt32 fails.

By auto number I assume you mean the result of the query, which would be done like this, if I recall correctly:

 string pcount = OpenConCls.reader[0].ToString();
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Depends on the contents of the file.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Here's an example that may help:

#include <stdio.h>
#include <stdlib.h>

double uniform_deviate(int seed)
{
    return seed * (1.0 / (RAND_MAX + 1.0));
}

int main(void)
{
    int lo = 3, hi = 50;

    for (int i = 0; i < 1000; i++) {
        double r = lo + uniform_deviate(rand()) * (hi - lo);
        int block = i + 1;

        printf("%f ", r);

        if ((block % 10) == 0) {
            putchar('\n');
        }

        if ((block % 100) == 0) {
            getchar(); // Pause
        }
    }

    return 0;
}

The trick is in the uniform_deviate function that takes the seed value and reduces it to a floating point value between 0 and 1. You can then multiply that accordingly to get a floating point value in the range you want.

The benefit is that you don't lose precision on the floating point value due to rand being strictly integer based, and I'd like to think it's an elegant solution to boot. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can pass through the identity and use it as a key into the database. Seems to me this is really a matter of finding a good piece of information from the authentication result that can be used to pull back a unique record from the database.

So the question might be how are you querying for a user record?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Personally I would only use async/await if you're running on the UI context as I believe that's the entire reason it was designed (to prevent blocking the UI thread)

So in your opinion it's just a more convenient form of BackgroundWorker?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Sounds illegal or at least against someone's EULA. We don't allow discussions of that nature.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

if i use this, something errors will come out in my original prog.

Post the errors and your updated code.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You need to include <string> for the string class, not <string.h>. The latter is for functions inherited from C.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Out of curiosity, since you're authenticating with LDAP, why not use LDAP for gathering user information as well? It sounds like the basic information is already part of an AD user record, so there's no point duplicating that information in another database.