deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why not just keep it simple?

int vowels = 0;
int other = 0;

for (int i = 0; myarray[i] != '\0'; i++) {
    switch (myarray[i]) {
    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
        ++vowels;
        break;
    default:
        ++other;
        break;
    }
}

cout << "Vowels: " << vowels << '\n' 
     << "Other: " << other << '\n';
Assembly Guy commented: Kudos +5
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why would every different shop have the same inventory? ;) But to answer your question, look into making the vector a static member of the base class. Then it will be shared across the board.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The strcmp() function compares the ASCII values of the characters one by one

It compares the numeric values of the characters. It's not safe to assume that the character set is ASCII. Granted, ASCII and Unicode (where ASCII is a subset) are pervasive, but but not universal.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It compares each character in turn. If they have the same numeric value, it moves to the next character. When a mismatch is found, it returns the difference of the two numeric values[1].

Positive and negative are easy to see when looking at the values as being numeric:

1 - 2 = negative
2 - 1 = positive
1 - 1 = 0

[1] That's all that's required by an implementation. Some implementations, like mine above, will enforce strict -1, 0, or +1 as the return value.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The two headers are completely different. cstring is inherited from C and provides functions for working with C-style strings (arrays of char terminated by '\0'). string was born in C++ and defines the std::string class along with its non-member functions.

strcmp works like this:

int strcmp(const char *a, const char *b)
{
    while (*a == *b) {
        if (*a == '\0') {
            return 0;
        }

        ++a;
        ++b;
    }

    return *a < *b ? -1 : +1;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

|| has lower precedence than &&. To get the appropriate behavior (granted I'm assuming what behavior you want), you need parentheses:

(gps == 'Y' || gps == 'y') && (childseat == 'N' || childseat == 'n')
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Go to your control panel, then enter Control Panel\Appearance and Personalization\Display into the address bar. Make sure the scaling level is set to 100%. When I upgraded to 8.1, it had it defaulted to 125% and your issue sounds like the one I was having.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

/^[[:alnum:]]*$/

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm not sure if ODBC works for Word, it would surprise me, to be honest.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But it must work if the Ms word is not present

That's what makes things difficult. If the Office API isn't available, you have no choice but to work around it somehow. I've done this when reading Excel files (ODBC works nicely), but not with Word.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm not sure, that's why I suggested research. ;) A quick search shows potential options, but I can't offer a recommendation without more extensive poking around.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

C++11 (3.6.1 Main Function)

"A program shall contain a global function called main, which is the designated start of the program. It is implementation-defined whether a program in a freestanding environment is required to define a main function. [Note: In a freestanding environment, start-up and termination is implementation-defined; startup contains the execution of constructors for objects of namespace scope with static storage duration; termination contains the execution of destructors for objects with static storage duration. —end note ]"

In other words, all bets are off in a freestanding environment. main can be required or not, and by extension, the signature defined for hosted environments is not required either.

Through a loophole in the wording, the C standard (up to and including C11) allows void main in a hosted environment provided int main is also supported. There too, all bets are off for freestanding environments. I'm not sure about C14 though, I haven't been keeping up with the bleeding edge of standardization.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

it's int main(), never void main() because main() always returns an integer back to the operating system.

Except when the program is freestanding and not hosted by an operating system. But if you're writing a freestanding program, you're probably not asking for help on a place like Daniweb. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You may want to do some research on the OpenXML file format, it's not as simple as raw text. For something like this I'd look for a library that extracts Word files and then place the (hopefully) formatted text in my control.

Aspose.Words is a good library for this that I use professionally, but it's not free.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The problem is when I login, it would only read one record.

That's exactly what you tell it to do. Technically, your file reading loop in login is pointless because the first iteration returns from the function in all cases.

I suspect you intended to return 0 only if the loop exits normally:

while(fscanf(fp,"%s\n%s %s\n%s\n", obj.employeeID, obj.employeeFN, obj.employeeLN, obj.employeePW) == 4){
  if(strcmpi(obj.employeeID,loginEmployeeID)==0 && strcmpi(obj.employeePW,loginEmployeePW)==0){
     return 1;
  }
  else if(strcmpi("admin",loginEmployeeID)==0 && strcmpi("admin",loginEmployeePW)==0){
     return 2;
  }
}

fclose(fp);

return 0;

Take a look at the loop condition as well; I fixed a bug for you. feof should not be used to control the loop. Due to timing of events, it introduces an off-by-one error where the last line may be processed twice.

Pia_1 commented: It works perfectly..thank you so much! +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My books show - and > but neither of them seem to apply. The books don't seem to show both together.

Strange books. -> is a single token, and should at the very least be mentioned in the precedence table for operators.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd recommend against that, actually. It makes managing the connection harder. Also, many database servers will support connection pooling to eliminate the performance cost of creating, opening, and closing a connection for each transaction.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm going to guess that mode_t is already defined as something like unsigned int, or maybe as an intrinsic type in your compiler. In that case, your define would end up being expanded as unsigned int int, which is an illegal type name.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please post the contents of my_global.h.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The percentage is a string, which makes things a bit more difficult as you have to convert that to something you can use in a mathematical expression. Let's say InsurancePercent is of the form "###%". The process would be some variant of this:

var percent = Convert.ToDouble(patient.InsurancePercentage.TrimEnd('%'));
var insuredAmount = patient.AmountDue * (percent / 100);

Console.WriteLine("Insured Amount: " + insuredAmount);
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i do always study but always forget..i feel sumties like stupid !!

You remember what you use often, and references are there for what you don't use often. Don't feel bad, there isn't a programmer in the world who can remember everything, and it gets harder to remember as you learn more.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can set the delimiter for getline().

Indeed, but only one delimiter. If the line doesn't end with '.', input will span multiple lines. A full solution would use getline from the file to read a whole line, then getline with '.' as the delimiter from a stringstream of that line:

string line;

while (getline(in, line)) {
    // Display the line header

    stringstream ss(line);
    string line_part;

    while (getline(ss, line_part, '.')) {
        // Display the line part
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My C/C++ classes swore by passing by reference as a good coding practice, and I have passed even primitive values by reference for a while now.

Even in C++ it's a tradeoff. The size of a reference versus the size of the object being passed relative to the cost of an extra level of indirection (even when it's hidden from you). Generally, in both C++ and C#, you can feel confident passing scalar types by value. Scalar types are things like char, int, double, decimal.

In C# you'll usually be passing by reference except in the odd cases where you're using a value type such as DateTime.

Even then, my recommendation is not to worry about it for performance reasons unless you have profiling results that show a slowdown, you've done everything you can at a higher level, and micromanaging how you pass parameters is the next step.

Instead, focus on functionality. If you want to update the object being passed either by reseating the reference or creating a reference from a value type so that it can be modified from another function, consider using either a ref or out parameter. Otherwise, use the default passing semantics for the type.

The trick is to do what you need to do when you need to do it and not before. Otherwise you'll end up with over-engineered code that's harder to maintain and may even be counterproductive in terms of performance.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The downside is that using namespace will make the entire namespace visible, even if you don't want all of the names to be visible. There's risk of naming clashes. Prefixing std:: is more verbose, but also imposes no risk of name clashes.

For namespace std, it's really just a matter of knowing what names are there and avoiding creating new names that match. But that's not as easy as it sounds, so the general best practice is to limit how many names you expose from a namespace.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Post your code and the examples that aren't working the way you think they should.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Start by making sure that your driver is working the way you want using a standard sorting library. Here's one that uses qsort in C-style since you're into C-style strings:

#include <cstdlib>  // std::qsort is here
#include <cstring>
#include <iostream>

using namespace std;

namespace {
    const int COUNTRY_MAX = 5;
    const int COUNTRY_NAME_MAX = 255;

    int compare(const void *a, const void *b)
    {
        return strcmp((const char*)a, (const char*)b);
    }
}

int main()
{
    char countries[COUNTRY_MAX][COUNTRY_NAME_MAX] = {0};

    cout << "Enter " << COUNTRY_MAX << " countries.\n";

    for (int i = 0; i < COUNTRY_MAX; i++) {
        cout << i + 1 << ": ";
        cin.getline(countries[i], COUNTRY_MAX);
    }

    qsort(countries, COUNTRY_MAX, COUNTRY_NAME_MAX, compare);

    for (int i = 0; i < COUNTRY_MAX; i++) {
        cout << countries[i] << '\n';
    }
}

If this is sufficient, you're done! Otherwise, you might be asked to write your own sorting function, which is relatively straightforward and also a good learning exercise.

Keep in mind that C-style strings are arrays and do not support direct assignment. You'd need to use something like strcpy (still thinking in C mode) to copy the content of the arrays.

On a side note, 20 is too small for country names. IIRC the longest official country name pushes 70 characters, and unofficial names push 200. The ideal would be to use std::string and let each object size itself properly so you don't need to worry about such things. An added benefit is that std::string supports copying with the …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What goober wrote those questions? Question 95 is especially entertaining given the acronym vomit of its multiple choice answers, but most of the questions are amusing.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd start with something like "Applicants must be of legal age in their country of citizenship". But this is definitely something that should be written with the consultation of a lawyer.

mmcdonald commented: Exactly what I was after +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Consider a linking table. Remove tecnico from agendamento_diario then add a new table for linking the two together:

agenda_link:
    agenda_id, tecnico_id
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

When you're storing a list of entities in a column, that suggests you have shared data which can be normalized. Let's take your names example and make up something to show the setup.

Denormalized

business_unit:
    bu_id, managers, address

-- Separating the manager names is a chore
select managers from business_unit where bu_id = @bu_id;

Normalized

business_unit:
    bu_id, address

employee:
    emp_id, bu_id, name, is_manager

-- Names are separated naturally
select name from employee where bu_id = @bu_id and is_manager;

One obvious benefit of this is the managers can be abstracted into employees and share the same table.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You're not assigning the text with correct formatting. Try this instead:

textBox1.Text = string.Format("{0}-{1:00000000}", pcount.Substring(0, 4), pcountAdd);
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can also simply click on the NEW icon next to the forum name (on the home page) to mark it as read.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Until you really know what you're doing, it's a good idea to compile code you want to show off before posting it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm here to ask a help because I am not a Expert like you I'm a newbie on C# program.

I'm happy to help, as evidenced by my posts in this thread. However, the purpose of helping is for you to learn. Eventually you should learn enough to not need to ask for help. As an example, I rarely ask others for help because I'm able to do research and think through my problems on my own.

When it seems like I'm being asked to do all of the work and thinking for you (such as fixing simple syntactic and semantic errors), I get the strong impression that you're not learning anything, and thus my help is pointless. If you can't do that much, you'll be right back here in no time asking for more "help".

I want a simple query to catering my needs.

At this point I'd question why you haven't managed to come up with something workable, or even something different from what you had originally. I've given you a lot of code, and plenty of ideas for moving forward. Barring doing it all for you including a sample database schema and complete working code, what more can I do for you?

Ketsuekiame commented: You can lead a horse to water... +10
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I got my Hypocrite Medal during a battle of words on the C++ forum

It's not easy to be consistent. Also, one's opinions may change over time, which can smell like hypocrisy but is really just adjusting to new experiences and knowledge.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

First and foremost, your code exhibits undefined behavior because you only ever initialize the first character of the string. The actual problem you're seeing though, is that you only store one character at a time in string[0], and it gets replaced with each iteration of the file reading loop.

The counter will only increment if the last character in the file is 'a', or the random memory used by string happens to have an 'a' in it.

A better approach would be to read a character, then check it:

int ch;

while ((ch = fgetc(f)) != EOF) {
    if (ch == 'a') {
        ++counter;
    }
}

fclose(f);
castajiz_2 commented: tnx! +3
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

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

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

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

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

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

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

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

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

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.