deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Define "swap" for your purpose. Do you want to swap the file references entirely or just copy the contents of one stream to another?

Or is there a way to get the name of the file that the fstream has open?

Nope. You need to save the name, which is easy by wrapping the whole shebang into another object that has two members: one for the stream and one for the file name.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

CSV is just a text format, so you'd open and read the file as you would any text file. However, you need to parse the format. For example using a very simple variant of CSV:

#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    ifstream in("file.csv");
    vector<vector<double>> fields;

    if (in) {
        string line;

        while (getline(in, line)) {
            stringstream sep(line);
            string field;

            fields.push_back(vector<double>());

            while (getline(sep, field, ',')) {
                fields.back().push_back(stod(field));
            }
        }
    }

    for (auto row : fields) {
        for (auto field : row) {
            cout << field << ' ';
        }

        cout << '\n';
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Daniweb is more of a Q&A forum for pointed questions and discussion. It's not well suited for teaching someone from scratch. Might I suggest Khan Academy?

ddanbe commented: Great suggestion! +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You're not using the sender parameter, so it can be anything (I'd just use Me). However, you are using the e parameter, so you need to fill out a new GridViewEventArgs object and pass it in:

Protected Sub btnEdit_Click(ByVal sender as Object, ByVal e As System.EventArgs) Handles btnEdit.Click
    Dim editArgs As New GridViewEditEventArgs With {.NewEditIndex = row}

    GridView1_RowEditing(Me, editArgs)
End Sub

In this case, row would be whatever row you want to edit. You may want to use the first selected index, or loop through all selected indices and call the RowEditing handler for each, but that's entirely application specific.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Have you tried an incremental sync? http://msdn.microsoft.com/en-us/library/bb726021.aspx

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A better question is why are you using the registry for your application in the first place? That's no longer best practice for arbitrary configuration.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You spelled "asset" wrong, for one thing. For another, I suspect you wanted to use splits in the foreach loop rather than assetClasses.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I've never experienced that problem

Just because you haven't experienced a problem doesn't mean it doesn't exist. Most of the time people who only use gets in toy programs and are the only ones typing input will pull out the "it's never happened to me" fallacy. Here's a socratic question:

char buf[10];
gets(buf);

What happens if in the above code, you type more than 9 characters? Further, what if stdin is redirected to a file that you don't control?

the only problem I've had from gets is that sometimes (I've only had one case of this) it get's skipped and you have to put the same gets function twice to prevent that

That's not a problem with gets. It's a problem with not understanding how stream I/O works. You're mixing formatted (ie. scanf) and unformatted (ie. gets) input such that the formatted input leaves a newline in the stream and the unformatted input successfully terminates on it immediately.

The usual recommendation to get around that problem is always use unformatted input from the source stream, then parse the result using something like sscanf.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can certainly use C# and .NET for desktop applications. While I do some web development at work, most of it is desktop/server apps and plugins.

In Visual Studio, simply choose to make a new Console, Windows Forms, or WPF project to get started. Though be aware that there are differences in terms of available UI controls, options, and ways of putting everything together that may complicate the learning curve relative to the web development you're used to.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The easiest command I've found to capture strings is "gets(string)" to set the string to your variable then just "puts(string)" to display it

Easiest, sure. But with that ease comes a significant and unavoidable risk of buffer overflow because gets doesn't know when to stop copying characters to the array, and there's no way to stop it.

fgets is only slightly more complicated, and much safer. You can still pair it with puts, though some introspection about the trailing newline (that gets throws away, but fgets stores) is needed:

if (fgets(string, sizeof string, stdin) != NULL) {
    char *p = strchr(string, '\n');

    if (*p == NULL) {
        // No newline, partial line was read
        panic("Unexpectedly long line);
    }

    *p = '\0'; // Trim the newline so puts works consistently

    puts(string);
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There's no rule against that, unless you start posting for the sole purpose of promoting the signature.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

that's why someone tell me for learn C# lol

C# has its own quirks that complicate the learning curve, so don't expect any magic by learning a different language. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Also, please provide the purpose of this program.

It's pretty obvious that the purpose is to populate an array from a function.

but you aren't returning the edited variable nor are you passing it by reference.

Arrays are passed by simulated reference (ie. by pointer), so there's nothing wrong there. The two issues are thus:

  1. Semantic error: size is not a compile-time constant, and C++ doesn't allow array sizes that are not compile-time constants.

  2. Syntax error: The subscript operator is not used when passing an array to a function, just the array name.

The corrections are simple and obvious, provided the OP doesn't want a dynamically sized array:

#include <iostream>

using namespace std;

void getdata(int a[], int size);

int main()
{
    const int size = 10;

    int a[size];

    getdata(a, size);

    return 0;
}

void getdata(int a[], int size)
{
    for (int i = 0; i < size; i++)
        cin >> a[i];
}

You might say that failing to use the populated array is an error as well, since the only way to confirm the code works is by stepping through it in a debugger.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't remember off the top of my head, but it's not more than 10. You should be able to add a signature now from here.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There are a few mistakes, to which one are you referring?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

here is the screen shot when i opened my file with notepad++.

...was it so hard to copy and paste a few lines from the file into your post?

Anyway, I'd recommend reading the whole line first to avoid the issue you're seeing. getline doesn't recognize line breaks unless you tell it to do so. You're telling it to stop on a comma or EOF, which means the last field on the first line is "4.0\n1". Consider this:

#include <fstream>
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main()
{
    ifstream in("test.txt");

    if (in) {
        string line;

        while (getline(in, line)) {
            stringstream sep(line);
            string field;

            getline(sep, field, ',');
            cout << "userid: " << field << '\n';

            getline(sep, field, ',');
            cout << "movieid: " << field << '\n';

            getline(sep, field, ',');
            cout << "rating: " << field << '\n';
        }
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

and what about my last post in which i posted one code ?

That's C++, not C. Can you post a sample of your file?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

One thing that should be noted is that the compiler can inline functions even when they're not declared as inline when it thinks doing so will be appropriate.

Also, inline is nothing more than a hint. The compiler is free to ignore it. That's one benefit (in a sea of downsides) to function-like macros: they're guaranteed inlining.

so, inline functions are always good to use in our code ?

I'd say the opposite. Inline functions are to be avoided until you can provide solid proof through a profiler that you've both got a bottleneck and that inline functions fix it. Otherwise they're not worth the hassle.

Can you please throw light on this statement ?

"the increased object code size results in excessive cache misses or thrashing."

Code gets loaded into memory in the form of instructions. You want your executing code to be loaded into a single cache line so that it's not swapped into RAM (slow) or even paged into virtual memory (hideously slow) an excessive number of times before completion.

When a function gets inlined, the calls are replaced with the whole of the function body rather than simply referencing the body through a call instruction, which can potentially increase your instruction size by orders of magnitude. So while you might save yourself the overhead of loading stack frames and executing call instructions, the overhead of duplicating code could cause you to cross those thresholds and be measurably slower than the …

nitin1 commented: awesome!! your way of explanation suits my understanding very much... +3
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@james sir, what are those "quoting" rules ?

Read the links provided in this thread.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's fairly easy to accomplish in either language.

True, provided the "CSV" file is actually a subset of CSV where each record is a single line and no quoting rules are in place. Properly parsing actual CSV files is not especially difficult, but it's not quite as easy as using fgets and strtok.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

so writing macro may increase time at compilation time, but shouldn't it help at execution time as we are saving our overheads in the funtionc calling.

Close. Inlined code through either an inline function or function-like macro can reduce execution performance if the increased object code size results in excessive cache misses or thrashing.

These days the overhead of a function call is negligible, so it shouldn't be your reason for introducing inline hints; there's more to that particular decision than call instructions and loading/unloading stack frames.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

let's leave it at that instead of squabbling?

Provided it remains civil, "squabbling" amongst experts is a very good thing because a lot of ideas and information get thrown around for people to learn from.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but learning how to use the rand() function in this manner will help me apply it to what I need it for.

These links may help for a general overview:

http://eternallyconfuzzled.com/arts/jsw_art_rand.aspx
http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_rand.aspx

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The X,Y coordinates for each particle on your 2D plane is the random location. If all you want to do is to output the random location for each particle, then my example program is sufficient.

rubberman commented: pairtickle - my pairtickle physicist wife will chuckle at that one! :-) +12
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

We require that you show some proof of effort before offering any significant help. Do you have a specific issue that you encountered when trying to answer the question?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Not enough information. Is this a Windows form? A web form? WPF? Are you doing it all programmatically or using the Visual Studio designer? Typically such basic questions are better answered with a beginner's tutorial or book.

ddanbe commented: Good answer +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You're conflating "random particles" with "random numbers". Since this is a 2D plane, each particle would presumably have a random X and Y coordinate:

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

struct pairtickle { int x, y; };

/**
    Generates a random particle given the upper bound
    of each coordinate. The lower bound is always 0.
*/
struct pairtickle random_particle(int x_max, int y_max)
{
    struct pairtickle result;

    result.x = rand() % x_max;
    result.y = rand() % y_max;

    return result;
}

int main(void)
{
    struct pairtickle particles[300];
    int i;

    /* Generate the 300 random particles */
    for (i = 0; i < 300; i++) {
        particles[i] = random_particle(20, 20);
    }

    /* Display them */
    for (i = 0; i < 300; i++) {
        printf("(%d,%d)\n", particles[i].x, particles[i].y);
    }

    return 0;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Me is the VB.NET equivalent of C#'s this. So in C# you'd write tinstaafl's suggestion as:

for (int i = 0; i < 4; i++)
{
    this.Controls("pictureBox" + i).Visible = true;
}

Though this depends on each PictureBox being default named as if you dropped them onto the form and didn't change the name. It also assumes that all four PictureBox controls exist directly on whatever control/form you're referencing by this.

All in all, pretty big assumptions given how vague your question is. I'm also not sure that the loop does what you want (actually, I'm pretty sure it doesn't). We need more information as to the exact behavior you're looking for before any specific suggestions can be made.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So any conclusion for this? Did you just say impossible?

I said virtually impossible. Meaning it's not impossible, but realistically it won't happen. That's your conclusion, and if it's not satisfactory for you, C++ isn't the only language out there that supports OOP.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@deceptikon, can you explain more? I didn't comprehend.

I can't really make it any simpler than this:

  1. The C++ standard doesn't currently allow it, and adding that feature in any useful way would be virtually impossible.
  2. Compiler support would be extremely difficult and error prone.

Just because something seems easy to you doesn't mean it's actually easy, especially when it comes to language and compiler design.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But why wouldn't the compiler just allocate space for those data members in use by that object?

Apparently you completely failed to read the second part of my response that explains exactly why the compiler wouldn't do it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Does compiler allocates or reserved memory space from the data member the are not in use?

Yes.

I think, compilers are smart enough to determine which data member are in use of that object and which are not. So is there a reason (WHY and WHY NOT) they (DO or DO NOT) allocate space those resources?

Determining which data members are used is the easy part. Generating and managing each individual object that may have different used members makes my brain hurt just thinking about it.

Not to mention the insane rules that would need to be in place in the language definition to give us any semblance of consistency between compilers. I suspect those rules would be so draconian that any benefit you think you could get from this feature would quickly be reduced to nothing for the sake of portability and backward compatibility.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your question is hopelessly vague. What is the "Borland C++ DLL"? Is it a DLL written and compiler using a Borland compiler? Is it some DLL shipped with the Borland compiler? Give us some details.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So what is the answer ?

The answer is "it depends". You need to consider several issues stemming from the platform and compiler, including but not limited to:

  • Are the combination of operators you use to mimic multiplication faster than multiplication on your target platform?

  • Does the compiler optimize * into either your own bit twiddling code or something even faster? Compiler writers are smart folks, and usually their solutions are vastly superior to ad hoc stuff from application programmers.

  • Does the compiler optimize the multiplication away entirely? It doesn't matter how clever your trick is to mimic multiplication if the compiler can beat it by emitting nothing.

  • Does your tricky code confuse the compiler's optimizer such that the resulting machine code is slower than the equivalent multiplication?

There's no single answer to the question as it's one of those cases where your only recourse is to break out the profiler and do empirical testing.

sepp2k commented: Well said. +6
nitin1 commented: as usual, 1 man army for problems :D +3
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Main problem is that most of the links are nofollow now a days.

Hmm, I wonder why that could be? :rolleyes:

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

im just gooing to leave this interesting article for the apple fans! :)

Hardly interesting. I've seen umpteen articles like that going in every direction, every which way, and always with different lists of features that are the "XYZ killer".

Though I especially enjoyed the mention of screen dimensions (a hardware feature) in a list comparing operating systems. Could the author not find enough legitimate OS features that "beat" iOS to make it a round 10? ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

if it has been done for once

How does it know? What if you've created other objects? What if those objects create objects behind the scenes or trigger events that spawn threads that create objects? It's not quite as simple as you seem to think, and you may be misunderstanding how the garbage collector works.

There's plenty of learning material on the .NET garbage collector. Maybe if you point to parts that you don't understand rather than paraphrasing how you think reality should work, it would be easier to help clarify things for you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If it's .NET, the garbage collector is running. Whether it actually does something is up for debate, but there basically won't be a time when you have to worry about manually managing memory for stuff that the garbage collector handles.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is this not correct?

Perfectly correct.

Generally in a conforming implementation foo = constant; foo == the_same_constant; should only ever produce false if foo and the constant have different types (and thus the assignment causes a conversion) - unless I'm missing something. Floating point inaccuracies should only bite you if you're doing arithmetic.

This is also the correct answer. As for why the OP's program failed to produce the correct behavior, we'd need to know details about the platform and compiler to diagnose non-conformancy. I'm willing to bet we're looking at a Turbo Crap quirk.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Most of us older folks lived our entire lives without a phone attached to our bodies, so what we never had we never miss.

And you walked 10 miles everywhere...up hill...both ways, and you were thankful for it. ;)

I didn't have a cell phone until my late 20s, but that doesn't make it any less useful to me now.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What's the purpose of the code?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Since floats are 32-bit values, you could pun them to an unsigned 32-bit integer, do the bit-wise operations, and then cast it back to a float.

Extremely risky with punning as you may hit a trap representation. Of course, you can safely cast the value to unsigned int, but that truncates the precision.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Bitwise operators don't work with floating point types. Really the best you can do is pun the float into an unsigned char pointer and perform the operation on that. However, this could easily produce results that you're not expecting or that are completely erroneous given the structure of floating point values in binary.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Do not go off and download cards.dll from some unknown website.

Obvious statement is obvious. Since we're talking about software development, one would hope that the OP isn't a moron and can discern the safe from the unsafe.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

return(count) invokes the constructor that takes an int, so you get a newly constructed counter object using count as the initializer.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think it is 1.79769e+308.

It's implementation defined.

It tells me not to use short.MaxValue so I assumed that numeric_limits::max will do the same as this?

The two are roughly synonymous. I suspect the comment is saying not to use short.MaxValue because short.MaxValue gives you 32767 rather than 32768, which breaks the algorithm.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

do you know where to get visualstudio that works on android platform?????????????????????

That's an easy one: nowhere. Visual Studio is a Windows desktop application. However, I know for a fact that there are Android apps that provide a C# compiler and IDE. How good they are I have no clue. You can also write C# online with sites like Ideone.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

cards.dll isn't installed with Windows 7, but if you Google it you'll be able to find any number of sources that have it available for download.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

NOTE: I can't type a literal asterisk here. It is being interpreted as the italic formatting code.

Use code or inline code tags and asterisks won't be interpreted as Markdown. If you want plain text, you can escape any markdown special character with a backslash.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I intend to switch to a Windows phone when I get tired of my 4S. ;p