deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I wouldn't recommend using %s unless you can guarantee that the fields won't contain embedded whitespace. Further, you should always use a field width for string specifiers in scanf to avoid buffer overflow.

Ignoring the possibility of quoted fields that contain embedded tabs, it's straightforward to read a line with fgets and then parse it with sscanf:

#include <stdio.h>

int main(void)
{
    FILE *in = fopen("input.txt", "r");

    if (in != NULL)
    {
        char line[1024];

        while (fgets(line, sizeof line, in) != NULL)
        {
            char field[1024];
            int offset = 0;

            // Break down the line based on tabs ('\n' included because fgets retains a newline if it's present)
            while (sscanf(line + offset, "%1023[^\t\n]", field) == 1)
            {
                puts(field);

                offset += strlen(field);

                // Safety check to avoid stepping off the end of the array
                if (line[offset] != '\0')
                {
                    ++offset;
                }
            }
        }

        fclose(in);
    }

    return 0;
}

Note the use of a scanset in scanf to look explicitly for tabs.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Example, I started off with console apps, I became comfortable with it.
I then started playing around with forms, the code stayed the same.
Then i created services, the code stayed the same.

If you mean the syntax of C#, then sure. But semantics and design can change considerably. Between a console app and a GUI app, the jump to event-driven behavior can be jarring. From personal experience, the jump from a GUI app to an ASP.NET app is quite jarring due to the stateless nature of a web app.

There's a huge learning curve if you know Windows Forms and move to WPF because the design process changes drastically.

Each technology has its own quirks and best practices.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Luckily for you, a lot of students try to cheat on these forums by posting their homework assignment. Just look through those to get ideas, but please don't post your solution for the cheaters to turn in.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

"Expert" is a tricky word. I wouldn't expect anyone to be an expert in one of those, much less all of them. However, being competent in all of them or even proficient is certainly possible.

Though Silverlight's lifetime is questionable. We're not sure if Microsoft will continue to expand and maintain it with the advent of HTML5. Windows Forms may have a similar fate.

The current du jour core technologies seem to be Entity Framework, WCF, MVC, WPF, and Azure.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Currency. {0:C} says that the first argument after the format string is to be formatted with the standard currency formatter.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Just the function or member function name won't do, the argument list is required even if it's empty. For example:

obj2->Landline(); // Notice the parentheses

Also note that you'll immediately get a runtime failure because obj2 doesn't point to anything. Either make it a regular object:

PCTL obj2;

...

obj2.Landline();

Or have the pointer point to an object:

PCTL base_obj;
PCTL *obj2 = &base_object;

obj2->Landline();
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Since you have free options of SQL Server, I see no reason to rely on Access databases. They're too restricted to be worth it most of the time.

p.s: i hope this was not against the rules "can i trust to Crd version of sql server 2012?

Discussion of cracked software (which is what I assume you mean with "Crd") is against the rules. And the answer to your question is no, you can't trust it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But why do some websites insist that my password HAS to have letters AND digits?

Mindless tradition, probably. For the longest time the bare minimum password policy was at least 8 characters including one upper case letter, one lower case letter, one number, and one special character.

These days a pass phrase is more secure due to its length, but many sites still have a character maximum and/or character combination checks that preclude a pass phrase. I can only assume it's because they follow "best practice" without putting any more thought into it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Because '!' and '}' have to be included in the try set. I'll put it a different way. Why is this loop?

for (int i = 0; i < 27; i++)
{
    for (int j = 0; j < 27; j++)
    {
        // Stuff
    }
}

Faster than this loop?

for (int i = 0; i < 127; i++)
{
    for (int j = 0; j < 127; j++)
    {
        // Stuff
    }
}

The same principle applies. The more you have to consider in what characters might be there, the longer it takes to actually identify them.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I might organize my database so that I could do something like this:

var presentation = from m in db.PresentationModules
                   where m.PresentationId = pid
                   orderby m.ModuleIndex
                   select new
                   {
                       Module = m,
                       Components = from c in db.ModuleComponents
                                    where c.ModuleIndex = m.ModuleIndex
                                    orderby c.ComponentIndex
                   };

That way I could select a collection of modules and module components tied to the user. The collection can then be used in a more convenient manner than diddling around with indexes.

ddanbe commented: Indeed eternally awesome! +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The idea of this tutorial is to give people the idea how to write sleep on their own. just as you can be asked to write sort or other function which already exist. its a tutorial not a cheat code.

Nobody is dismissing your code as useless. We're simply highlighting issues that anyone who uses it should be aware of.

Here's a portable version that uses time_t:

void s_sleep(double seconds)
{
    time_t start = time(0);

    while (difftime(time(0), start) <= seconds)
        ;
}

You can certainly pass fractions of a second, but there's no guarantee that the timing will be accurate beyond a whole second. The difference is that instead of directly using arithmetic on time_t, difftime handles the comparison portably.

With clock_t, you can get a slightly better result, but it's not portable. However, in practice it's unlikely to fail (which, it's important to note, is the same with time_t):

void ms_sleep(int milliseconds)
{
    clock_t start = clock();
    int clocks_per_ms = CLOCKS_PER_SEC / 1000;

    while (((double)clock() - start) / clocks_per_ms < milliseconds)
        ;
}

For quick and dirty, one of these would be my go to function.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There is no sleep function that is 100% accurate

It really depends on what granularity you're looking for. More precise timing becomes more and more difficult, as you mentioned, for various reasons. However, time_t is only guaranteed to be accurate to the second. clock_t is better, but the granularity varies by implementation.

I'd be vastly more concerned about a busy loop than precision in all but the most extreme of cases.

Ancient Dragon commented: Agree :) +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

2014: The usual evening, an inconvenient day off, and now I have to remember to write 2014 instead of 2013.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't mind indeterminate values at all if I access an array with no initial value. I just don't want my program crashing because of some undefined behaviour that I don't understand.

Those two sentences are contradictory.

I don't understand traps by just looking at it either.

Imagine calling abort, but without the happy result for a user. ;) I wouldn't wish troubleshooting a trap representation on even the worst of my enemies.

I asked someone why it was undefined and they said to me that the OS only gives memory to a variable when it has a value otherwise nothing happens :S

Wow, that was a stupid answer. Whoever told you that is quite confused. You get memory, you just can't necessarily predict the contents of that memory.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why is accessing data in an uninitialised array undefined behaviour?

It really depends on where the array is defined. If it's a local array then it's undefined behavior just as accessing an uninitialized variable is undefined behavior. The contents of the array are indeterminate, which is the "official" reason for the undefined behavior.

The practical reason is that accessing random bits can trigger something like a trap representation and totally blow up your application simply by looking at a value.

Any ideas what I could do to keep the speed of uninitialising without breaking any rules?

I'd need more details on what you're using the array for. Restructuring the array so you only access it sequentially rather than randomly would be a good start, but that's not always appropriate for the problem.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The first chunk below lines up the decimals, but my "$"'s are too far, the second one fixes that and then the decimals are all F'd.

Right. The modifiers apply to the next item. If you don't want the "$" to be the next item, move it to before the modifiers:

cout << "$ " << fixed << setprecision(2) << setw(8) << right << 22.0 << endl;
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How are the weapons stored? Are they always a string in display format? Because it would be easier to have a weapon class that separates these things and makes it easier to work with:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

struct Weapon {
    string _name;
    int _damage;
    int _value;

    Weapon()
        : _name(""), _damage(0), _value(-1)
    {}

    Weapon(const string& name, int damage, int value)
        : _name(name), _damage(damage), _value(value)
    {}
};

map<string, Weapon> supported_weapons = {
    {"Fist", Weapon("Fist", 1, -1)},
    {"Masamune", Weapon("Masamune", 52, 750)}
};

class Adventurer {
    vector<Weapon> _weapon_inventory;
    Weapon _equipped_weapon;
    int _base_damage;
public:
    Adventurer(int base_damage = 1)
        : _base_damage(base_damage)
    {
        _weapon_inventory.push_back(supported_weapons["Fist"]);
        equip("Fist");
    }

    void add_weapon(Weapon weapon)
    {
        _weapon_inventory.push_back(weapon);
    }

    Weapon equipped_weapon() const
    {
        return _equipped_weapon;
    }

    bool equip(const string& name)
    {
        auto match = find_if(
            _weapon_inventory.begin(), 
            _weapon_inventory.end(), 
            [&name](const Weapon& weapon) { return weapon._name == name; });

        if (match != _weapon_inventory.end()) {
            _equipped_weapon = *match;
            return true;
        }
        else {
            return false; // Weapon not available
        }
    }

    int roll_damage() const
    {
        return 1 + rand() % (_base_damage + _equipped_weapon._damage);
    }
};

In your code you might do something like this:

cout << "Choose a weapon to equip: ";

if (getline(cin, name) && equip(name)) {
    cout << name << " equipped\n";
}
else {
    cout << "Could not equip selected weapon\n";
}
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

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

|| 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

In my job I tend to write a lot of Windows services. Due to this I've pared it down to bare essentials so that the code is as simple as possible, but still fully functional for the needs of each service. What this generally means is I don't use the service project in Visual Studio, instead favoring template code. After learning how services work, I found that the project was unnecessarily complex.

Barring an installer, the basic project would have only two files:

  • Program.cs: Setup and startup
  • Service.cs: The actual service

I usually separate the service from a service worker that does actual work, but that's application specific.

Program.cs sets up logging, any custom application settings, and runs the service normally. However, over the years I've found that a debug mode for my services is invaluable in both development and after deployment. If the executable is run interactively, it runs in a console and displays logging there as well. Here's a sample template for Program.cs:

public class Program
{
    /// <summary>
    /// Gets or sets the application's data folder.
    /// </summary>
    public static string ApplicationFolder { get; set; }

    /// <summary>
    /// Gets or sets the location of the file log.
    /// </summary>
    public static string LogFolder { get; set; }

    /// <summary>
    /// Gets or sets the log manager for the application.
    /// </summary>
    public static LogManager Log { get; private set; }

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    public static …
Ketsuekiame commented: Good service foundation template +11
ddanbe commented: Nice! +15
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

which would mean stable_sort would arrange those string with the same length in alphabetical order, is it?

No, stable_sort would retain the original order of those strings with the same length.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I can play that game too.

We won't do your homework for you. What have you tried?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My usual answer to "I don't know how to start" is, did you pay attention in class? If you didn't, it's tough love, but I'd say that you deserve to fail and should learn the lesson: Nobody will bail you out. It's a lesson that should be learned early, because it's a hard lesson, and it's reality.

I want to help you, I really do. But at this point the only way to do that is to do at least a large part of your homework for you. And from that you learn nothing.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

"Help" does not mean "do it for me". Post your code, ask a real question, and stop appearing as if you're trying to cheat on your homework.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You're probably one of the most unpopular posters DW has ever had.

I can think of a few that would vie for that title, but they gave up fairly quickly long before voting was introduced.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Little do they know that we geeks don't let mere holidays keep us from Daniweb. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Done :)

The result set must include delimiters, not remove them. ;) Try this little one-liner:

var parts = Regex.Split("abc,123.xyz;praise;end,file,clear", @"([\.,;])");
ddanbe commented: Nice! +14
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

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

So pass by reference basically boxes, or stores a pointer to the data type provided in the heap.

No. Passing by reference doesn't box a value type. Let's also differentiate between passing by reference and passing an object reference:

void foo(object obj);     // Passing an object reference
void foo(ref object obj); // Passing by reference

When passing an object reference, the reference to an object is passed by value. When a value type is passed by reference, compiler magic allows the called method to access the original entity.

This address in the heap is passed to the method.

Not necessarily. Deep under the hood you may ultimately have a pointer (another object holding an address), but it's equally likely that the compiler is smart enough to simply bind another symbol in the symbol table to the same address and avoid any kind of indirection.

However, if a pointer is used, you introduce the overhead of fetching the object at that address. This can overwhelm any savings you might get from the performance of minimizing copying in the method call.

Given this, it would be more efficient in all situations to pass by reference rather than copy the whole value in a pass by value operation.

Would it? Try writing a test where you call a method with a value parameter in a long loop and profile it. Then do the same for a long loop that calls a method with a ref …

Ketsuekiame commented: +1 This kind of micro-management is very rarely required. +11
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A DataTable is the back end container for data, it corresponds roughly to a database table. A DataGrid or DataGridView is a UI control for displaying tabular data. It may or may not bind to a DataTable.

I'm not sure what controls those applications use, they may be custom grid controls. But it's safe to say that they use something like a DataGridView.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can Any body do it????

Yes. But nobody will do it for you. Please read our rules.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

<M/> - It is just the first letter of my first name within tags...

Is it meta? Does it mean you have no value? ;)

Oh the fun of reading way too much into things.

<M/> commented: lol +0
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

Hey, I have an idea! How about you do your own homework instead of asking other people to help you cheat?

nahi commented: tebeda +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please post your question in English.

Hinata_Dev commented: ok :) +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If that prank were real, and I strongly doubt it was, asking about his daughter as a first priority was totally evidence of good character.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but seriosly, the drinking age should be increased... (my opinion)

Age doesn't equate to maturity, unfortunately.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I just know that my client has a 12-man strong in-house legal team; so I'm sure they'll figure out the rest and make it happen.

12 lawyers weren't able to come up with air tight wording for this and asked a non-lawyer to get the opinions of other non-lawyers? Hmm.

<M/> commented: lol +0
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

if u dont have an answer to my post>>>>>>>>>>>>>>>>>>>>just SHUT up .

Last I checked, this was a public forum. AD makes a good point. Your writing style makes a strong first impression, and it's not a good one.

That said, I have an answer to your post. Discussion of writing exploits is against Daniweb's rules. Please find help cracking into systems elsewhere.

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

A segmentation fault means you accessed memory you don't own. The two most common causes are a pointer that's not properly initialized an an index outside the bounds of an array. Trace through your code and ensure that all of your pointers point to enough memory, then make sure all of your indexes are within those bounds.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster