deceptikon 1,790 Code Sniper Team Colleague Featured Poster

no its not ,, I SWEAR :D

"Homework" is a catchall term in our rules. Just because the exercise wasn't assigned to you by a teacher in a programming class doesn't invalidate the rule or the reason for putting the rule in place.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

btw its not homework

If you're learning C++ and this is a learning exercise, it's homework.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes we can. We won't though, as you'd learn nothing by being given the code for your homework exercise. However, we can help you along if you post your code and describe what you've tried as well as how it didn't work.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That's because your stringstream really does only contain the first word. Why? You used operator>> to populate mystring from cin, and operator>> stops reading at whitespace. Try using getline instead.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@deceptikon: I got this error,.

Did you even try to turn on your brain concerning these errors? Especially since I made a similar typo in an earlier post; the first error should be result.Rows.Count. The second should be result.Rows[0]["piId"].ToString().

Of course, this would be immediately obvious upon seeing the errors and consulting the documentation for DataRowCollection and DataTable. Don't expect my code to be perfect, and if I'm not able to help you quickly, you'd be on your own anyway.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

C doesn't have a string type. Can you be more specific about what you're trying to do? Perhaps post a sample program?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My understanding of fgetc is it reads character by character of a file

It reads one character from a stream. The stream may or may not be a stream to a file. For example, fgetc(stdin) is perfectly acceptable.

They think fscanf can also read character by character of a file. I do not think that is correct.

It can. The call that's equivalent to fgetc is fscanf(stream, "%c", &myChar).

I think fscanf is used for reading an entire file.

No.

but I have used it for reading an entire file before

It's possible with a single call, but very dependent on the format of the file. Most of the time you read lines from a file in a loop rather than everything.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's a pointer to int, but you want to print a string... How exactly do you want that string to be represented?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You didn't add your output parameter.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How are you calling the stored procedure?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is that corrrect?

Not at all. Have you checked a C reference manual? The only similarities fgetc and fscanf have is they read input from a stream, and fscanf can simulate fgetc.

The people you were arguing with, what were their points? Perhaps we can clear up any errors on both sides if you elaborate.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What if it isn't homework

Irrelevant. The homework clause applies universally to "do it for me" requests. It's merely called the "homework" clause because most violations are school exercises.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can we help? Absolutely. Will we help? That depends solely on how much effort you're willing to put in. If you just want someone to do it for you, you'll get no help. Our homework rule is very clear on that matter.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is your file already in memory or are you retrieving new strings from the file each time?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I've had issues with older games that ran fine on Windows 7. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What is actually the big mistake in my solution please advice so I can avoid it?

There's no big mistake, but you can do it better as per my examples. "Better" in this case meaning more flexible and easier to match the HTTP standard.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can check the compatibility center for software and hardware. Incompatible doesn't mean it won't work, but it might take some finagling to get it to work.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can get the most recent identity with scope_identity():

begin
    insert into np_Profesori (Ime, Prezime) values (@ime, @prezime);

    select @id = scope_identity();

    insert into npGdjeRadi (IDProfesor, IDFakultet) values (@id, @fakultet);
    insert into np_DodavanjeProfesora (IDProfesor, Added, AddedBy) values (@id, @added, @addedby);
end
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
Why Use Arrays?

Let's begin by considering why arrays might be needed. What is the problem that this feature solves? How does it make your life as a programmer easier? When studying new features, it's important to recognize what that feature does for you and where the incentive is in using it. Otherwise you might learn a feature just because it's there, but never actually use it, or never learn it at all.

Fortunately, arrays are very easy to justify. Consider a small program that collects 5 names and displays them to the user:

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string name1, name2, name3, name4, name5;
    int n = 0;

    cout << "Enter 5 names (EOF to stop): ";

    if (getline(cin, name1)) {
        ++n;
    }

    if (getline(cin, name2)) {
        ++n;
    }

    if (getline(cin, name3)) {
        ++n;
    }

    if (getline(cin, name4)) {
        ++n;
    }

    if (getline(cin, name5)) {
        ++n;
    }

    if (n > 0) {
        cout << "Name 1: " << name1 << '\n';
    }

    if (n > 1) {
        cout << "Name 2: " << name2 << '\n';
    }

    if (n > 2) {
        cout << "Name 3: " << name3 << '\n';
    }

    if (n > 3) {
        cout << "Name 4: " << name4 << '\n';
    }

    if (n > 4) {
        cout << "Name 5: " << name5 << '\n';
    }
}

We can immediately see that this is tedious and repetitive. It encourages copy/paste and is easy to make mistakes …

Assembly Guy commented: Good work, have some more rep :P +5
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There's nothing in those snippets that would make me suspect the map as cause for a memory leak. If the map itself is confirmed to be using "lots" of memory, my first question would be how many phone numbers are stored, and are all of them validated to actually be phone numbers?

It could be perfectly normal behavior if you have oodles of phone numbers.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But don't compilers typically like to pad structs so that they are aligned a certain way (Like making the size a multiple of four)?

Typically, yes, though how padding is added and how much greatly depends on the compiler. It also depends on the ordering of the structure's members.

Of more concern than char versus char* is that each node only holds a single character, yet there's memory allocated for two links and an integer ID on top of that character. It may be easier to reason about such a linked list, but it's terribly wasteful of memory.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think the example you gave me is quite similar is just that you are taking in the full list of methods not just purely get and post.

Of course it's similar because it's doing roughly the same thing. The difference is that instead of just taking a single request line and parsing it directly, you're programming against a standard document with semantic validation as well as syntactic validation.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

OkSoLve it if u can ;)

Done. Your turn.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

without typecasting, can i get the adressed values?

Nope. You can get just the bytes of the pointed to value by casting to char*, but without knowing what they represent, it's not terribly useful.

seems that i can't see what it is the type

You knew the type when you assigned a value to that void pointer, right? Save it so that you can recall it later.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Just dereference it: *obj.Vvariant. But since pointers to void cannot be dereferenced, you still need to cast Vvariant to something else.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Any hint on how to parse properly the HTTP protocol ?

Study the HTTP protocol defined in RFC 2616, and write code that meets all of the requirements. Parsing can be a deep topic, but depending on your needs it can be relatively simple. For example, here's a basic parser for the request line:

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

#define length(array) (sizeof (array) / sizeof *(array))

typedef struct request_line {
    char *method;
    char *uri;
    char *version;
} request_line;

char **split(const char *s, const char *delim, size_t *n)
{
    char *copy = _strdup(s), *tok;
    char **result = NULL;

    *n = 0;

    for (tok = strtok(copy, delim); tok != NULL; tok = strtok(NULL, delim)) {
        result = realloc(result, ++(*n) * sizeof *result);
        result[*n - 1] = _strdup(tok);
    }

    return result;
}

request_line parse_request_line(const char *s)
{
    request_line result = {"", "", ""};

    const char *methods[] = {
        "OPTIONS", "GET", "HEAD", "POST", "PUT", "DELETE", "TRACE", "CONNECT"
    };
    size_t n = 0, i;
    char **parts = split(s, " ", &n);

    if (n != 3) {
        // Invalid format, missing one or more parts
        return result;
    }

    for (i = 0; i < length(methods); i++) {
        if (strcmp(_strupr(parts[0]), methods[i]) == 0) {
            break;
        }
    }

    if (i == length(methods)) {
        // Unrecognized method
        return result;
    }

    // More validation can be added here

    result.method = parts[0];
    result.uri = parts[1];
    result.version = parts[2];

    return result;
}

int main(void)
{
    request_line request = parse_request_line("GET /mail/ HTTP/1.1\r\n");

    printf("HTTP Version: %s\n", request.version);
    printf("Method: …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The ideal would be to properly parse the HTTP protocol format, but for this specific case it's straightforward to extract the address (error handling omitted for brevity):

#include <stdio.h>
#include <string.h>

int main(void)
{
    const char *request = "GET /mail/ HTTP/1.1\r\n";
    const char *paddr_begin = request  + 4;
    const char *paddr_end = strstr(paddr_begin, "HTTP/1.") - 1;
    char addr[BUFSIZ];

    addr[0] = '\0';
    strncat(addr, paddr_begin, paddr_end - paddr_begin);

    printf(">%s<\n", addr);

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

I listed this in the C++ category.

To clarify, did you intend to do that? If not, I'll move the thread. If so, please explain how this thread is relevant to C++ since the code you posted is clearly Java.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

When I import the DLL I have created into another project to test, it complains about missing the reference

System.Drawing.Bitmap is a .NET standard class. The library assembly itself doesn't require you reference System.Drawing in the application that references your library, but if you expose the Bitmap class as a parameter or return value and require the application to recognize objects of it by type then the application does indeed need to reference System.Drawing because now that dependency is in the application.

You can eliminate that dependency by writing a wrapper around Bitmap within your library that only exposes features you'll be using. The application will use that class, and Bitmap will be hidden within it.

Here's a related example. I wanted to use the Aspose barcode recognition library in a DLL without forcing the application to reference or license that library. There was one type I couldn't expose: BarCodeReadType. What I did was create my own enumeration for the barcode type and my own Barcode class to hold the data:

/// <summary>
/// Represents supported barcode symbologies.
/// </summary>
[Flags]
public enum BarcodeType : long
{
    Codabar = BarCodeReadType.Codabar,
    Code11 = BarCodeReadType.Code11,
    Code128 = BarCodeReadType.Code128,
    Code39Standard = BarCodeReadType.Code39Standard,
    Code39Extended = BarCodeReadType.Code39Extended,
    Code93Standard = BarCodeReadType.Code93Standard,
    Code93Extended = BarCodeReadType.Code93Extended,
    Datamatrix = BarCodeReadType.DataMatrix,
    Ean13 = BarCodeReadType.EAN13,
    Ean8 = BarCodeReadType.EAN8,
    Patch = BarCodeReadType.PatchCode,
    Pdf417 = BarCodeReadType.Pdf417,
    Postnet = BarCodeReadType.Postnet,
    Qr = BarCodeReadType.QR,
    Upca = BarCodeReadType.UPCA,
    Upce = BarCodeReadType.UPCE
}

/// <summary>
/// Contains information for extracted barcodes.
/// </summary>
public …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Oh really?

Yes. The bit pattern will be different depending on the endianness of the architecture. There aren't any rules aside from being aware of the architecture and matching it, but a common guideline for portable code is to always use the same endianness for sharing bytes regardless of the architecture. The application then reorders bytes to match its own architecture.

For example, you'll notice that internet standard transmissions are big endian to maintain consistency.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

the language isn't changing at all. a lot of people are just either too lazy, too uninterested, or, in some cases, too dumb to learn and use it right.

Formal rules, good ones at least, are derived from common usage, so the language is indeed changing. Also, common usage tends to eliminate useless or awkward rules over time. Splitting infinitives and ending a sentence with a preposition are two good examples of awkward and unnecessary rules.

"Do not split infinitives" is a "rule" (note that it's technically not even a legitimate rule) taken from Latin then bastardized to fit English, but in Latin it's grammatically impossible to split an infinitive. In English it limits expressiveness and encourages awkward clauses.

"Do not end a sentence with a preposition" also damages expressiveness, and also happens to not be a legitimate rule. The reason for the rule is that a preposition ending is supposedly weak, but given the awkward sentence construction required to follow the rule in many cases, you end up with a weak sentence in general.

The me and I difference is quite subtle, and I prefer not to expect anyone to get it right. My biggest pet peeve is misuse of your/you're or their/they're/there.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

you can use assert to verify the datatype entered if its a type int or char then make your decision

assert shouldn't be used for input validation because if it fails, the program hard aborts. Assertions should only be used for cases that you expect to always be true in correct code; they're for helping to ensure that your code is indeed correct before shipping it. If an assert fails, it means the programmer screwed up, not the user.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Either one would work, and neither will negate the very clear issue of having two pointers and an integer for every character stored in the list. This is excessive memory usage that can and probably should be mitigated by storing an array of characters in each node rather than a single character.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Open it in a your debugger, and look at the xDoc object.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I made sure to include two classes, Main and Settings to show you where each piece should be. Without more complete code on your part, I can't really help more than that.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You're not seeing results because you're creating a whole different Main form object and calling the method on that one rather than the actual main form that's been shown.

In this case I'd add an event to your Settings form that gets fired when the button is clicked. The Main form will handle that eventand call its own MasterReset. For example:

public class Main : Form
{
    private void buttonOpenSettings_Click(object sender, EventArgs e)
    {
        using (var dlg = new Settings())
        {
            dlg.ResetSettings += Main_ResetSettings;
            dlg.ShowDialog();
        }
    }

    private void Main_ResetSettings(object sender, EventArgs e)
    {
        MasterReset();
    }

    private void MasterReset()
    {
        ...
    }
}

public class Settings : Form
{
    public event EventHandler ResetSettings = (sender, e) => {};

    protected void OnResetSettings()
    {
        ResetSettings(this, EventArgs.Empty);
    }

    private void buttonReset_Click(object sender, EventArgs e)
    {
        OnResetSettings();
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The error is very clear, you can't have a ref parameter that's a property. Copy the value of the property into a temporary variable, then after the method returns, copy that temporary variable's value back to the propery.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Because C++ demands that functions are defined before they are used

It's important to make a distinction between a declaration and a definition. Only a declaration is required to compile the code, but a definition is required to link it. Prototypes are declarations, they introduce the function signature.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster
  • Ease of use: Really depends on what you're used to. Both are user-friendly, IMO.
  • Availability of Software: Depends on what software you want. Games are notable in being more available on Windows, but that's slowly changing.
  • Overall Security: This is a tough one because security is dependent on what you're securing against and what the environment is.
  • Virus Attacks: Windows is overwhelmingly the more attacked platform because it's more pervasive. Think of it in terms of cost versus return. As an attacker, you get more out of a Windows virus because there are more Windows systems to attack.
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can, but functions must be declared before their first use, which means you need to add prototypes for the formula functions before main, and the definitions after main:

#include <iostream>
#include <stdlib.h>
using namespace std;

double fIntoCm(double dIn);
double fYtoM(double dY);
double fOtoM(double dO);
double fMtoKm(double dMl);
double fCmtoIn(double dCm);
double fMtoY(double dM);
double fMltoO(double dMl);
double fKmtoMl(double dKm);

int main()
{
    ...
}

double fIntoCm(double dIn)
{
    double dCm;
    dCm = dIn*2.54;
    return (dCm);
}

double fYtoM(double dY)
{
    double dM;
    dM = dY*0.914;
    return (dM);
}

double fOtoM(double dO)
{
    double dM2;
    dM2 = dO*29.574;
    return (dM2);
}

double fMtoKm(double dMl)
{
    double dKm;
    dKm = dMl*1.61;
    return (dKm);
}

double fCmtoIn(double dCm)
{
    double dIn;
    dIn = dCm*0.394;
    return (dIn);
}

double fMtoY(double dM)
{
    double dY;
    dY = dM*1.094;
    return (dY);
}

double fMltoO(double dMl)
{
    double dO;
    dO = dMl*0.034;
    return (dO);
}

double fKmtoMl(double dKm)
{
    double dMl;
    dMl = dKm*0.621;
    return (dMl);
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

In your FormClosing event, make sure that xDoc actually contains everything you want before calling Save.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Post your code using malloc, because that's what you need. The process is as follows:

  1. For new objects, call malloc to allocate new memory.
  2. For existing objects, call malloc to allocate new memory, copy the data, then free the old memory.
  3. Always call free to release memory in the destructor.

strupr typically doesn't allocate memory for you, so that doesn't count.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'll answer your question with another question:

free(thestring);
memcpy(thestring,str,strlen(str) + 1);

Where does thestring point after you call free?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There's no function for this, use strcmp in a loop.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster
while (true) {
    cout << "Social Security number without hyphens: ";
    getline(cin, ssn);

    if (verifyNumeric(ssn) == 'Y') {
        break;
    }
    else {
        cout << "Invalid input, try again: ";
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I also have the benefit of many years of experience which have taught me that there are many cases where the slick or clever solution is not the desirable (ie maintainable) solution.

That's a good point. I've found (also through experience) to start with the simple and obvious solution and only get clever when that doesn't work out for some reason. The reason is usually performance, but that's not as common as some would have you believe.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The short answer is that you can't control the user. Accept any string and then validate that it's what your program can process. If it isn't discard the string and ask for another one.

The long answer is that you can do it, but it's more trouble than it's worth in a console mode program. The ideal would be to use a GUI where an input control only allows numbers, but that's probably too much at the moment.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

No offense intended, but I don't like your OpenConCls. Here's a data access manager that I use for simplified database connections. Warning, it's a utility class, so there's a bunch of code. But first, an example of how to use it in the code you have:

Example Usage
private const string _provider = "MySql.Data.MySqlClient";
private const string _connectionString = "uid=root; database=membership; pooling = false; convert zero datetime=True";

private void Form1_Load(object sender, EventArgs e)
{
    try
    {
        using (var db = new DataAccessManager(_provider, _connectionString))
        {
            var query =
                "select top 1 piId" +
                "from tblpair_individual_membership" +
                "order by piId desc";
            var result = db.Select(query);

            if (result.Rows > 0)
            {
                _lastId = result[0]["piId"].ToString();
            }
        }
    }
    catch (DataAccessException ex)
    {
        // Handle the error
    }
}

DataAccessManager is generalized to any supported provider, which in your case is MySql.Data.MySqlClient. Note that I haven't added scalar query support because I tend to need full DataTables, but it would be trivial to add. It's also optimized for SQL Server in terms of the connection string features, but the actual data access should work for any provider (including MySql).

DataAccessManager
using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;

namespace JRD.Utilities.Data
{
    /// <summary>
    /// Provides data provider agnostic queries and commands.
    /// </summary>
    public class DataAccessManager : IDisposable
    {
        private DbProviderFactory ProviderFactory { get; set; }

        /// <summary>
        /// Gets or sets the external data store provider name (ex. System.Data.SqlClient).
        /// </summary>
        public string ProviderName { get; set; }

        /// …
ddanbe commented: Wow. +15
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

(pointer to array, dynamic memory , pointer to function , pointer to pointer ,types of pointers like near pointer , far pointer etc) are the other aspects that make the pointer hard.

  • Pointer to array: doesn't change the rules
  • Dynamic memory: doesn't change the rules in terms of pointers, dynamic memory is a different thing that happens to make use of pointers. Are we now saying that pointers are hard because of anything under the sun that might use them? If so, then any fundamental feature of C++ is "hard".
  • Pointer to function: actually changes two rules, they can't point to null, and they can't be generalized with void*. Pointers to functions are actually simpler than object pointers.
  • Near and far pointers: died with DOS.

The hardness of pointers isn't about pointers, it's about wrapping your head around a design that uses them. For example, linked data structures can use a lot of pointers that can be linked together in confusing ways. Or they can use a lot of pointers linked together intuitively. If you write spaghetti logic, it won't matter if you use pointers or not; the logic will be hard to manage.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

what is bs?

BindingSource