deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Do you have a question?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm guessing you don't mean by way of an interactive menuing system, since that's the obvious answer to your question. What exactly are you trying to accomplish?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Insufficient information. Were you given nothing else but a vague title for your report?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

&& is bitwise AND operator.

&& is the logical AND operator.

& is refrencing operator.

& is an overloaded operator in C, but in this case it's the bitwise AND operator.

& cannot be used instead of &&.

It can in some places, but you're limited by the type restriction of bitwise operators and the lack of short circuiting. It's strongly recommended that one not mix the two, lest one be surprised by the resulting behavior.

Performance doesn't enter the picture, especially when micromanaging performance at such a low level is the wrong place 9 times out of 10.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please read the code I posted very carefully. A single backslash and two backslashes in a string literal are very different things.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I see there it needed to be reveresed.

Yes, that's one. The other is what happens if you type nothing but 0? The output should be "zero", but nothing happens because your loop stops when value is 0.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What it does is it freezes you entire main thread in your program for the length of the durration

No, it causes the current thread to go to sleep for the specified duration. The logical next step is to use a separate thread for your UI (or a BackgroundWorker), if you need to perform work while also signaling updates to the UI. Oddly enough, minimal research into Thread.Sleep and the problem of UI updates will produce exactly that information. So strange... :rolleyes:

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think you're confused about the string passed to ofstream for opening a file. It's the file path, not the folder. So for each file, you need to make sure that the folder is included in the path. In other words:

std::string name = "outputBOHE " + NumberToString(cr_w) +" x "+   NumberToString(cr_h)+".pgm";
std::string path = "C:\\Cpp\\Project\\filter\\" + name;

ofstream fout (path.c_str());

fout <<"P2\n"<<nc<<'\t'<<nl<<endl<<cr_w<<'\t'<<cr_h<<endl<<255<<endl;

...
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It will extract each digit before comparing.

You introduced two bugs. One is easy to see and the other is a failure to account for edge cases. See if you can find them.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

can you please tell what data was there in $viagens['HoraPartida'].

My guess would be a time string in hours and minutes: "hh:mm". A better question would be what result is the OP expecting and how does the code not produce the correct result?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Then use getchar instead of scanf to read each digit as a character. Much easier:

#include <ctype.h>
#include <stdio.h>

int main(void)
{
    int ch;

    while (isdigit(ch = getchar()))
    {
        switch (ch)
        {
        case '0': fputs("zero ", stdout); break;
        case '1': fputs("one ", stdout); break;
        case '2': fputs("two ", stdout); break;
        case '3': fputs("three ", stdout); break;
        case '4': fputs("four ", stdout); break;
        case '5': fputs("five ", stdout); break;
        case '6': fputs("six ", stdout); break;
        case '7': fputs("seven ", stdout); break;
        case '8': fputs("eight ", stdout); break;
        case '9': fputs("nine ", stdout); break;
        }
    }

    putchar('\n');

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

rundll32.exe is a Windows application that executes shared stuff from DLLs. It's totally legit, so no worries about malware, but if it regularly eats CPU like that while idle you may be looking at a poorly developed DLL that's eating more CPU than it should.

You can find out what DLL rundll32 is running by opening Task Manager, selecting the Processes tab, and making sure the Command Line column is visible. That column will show what argument rundll32 was given.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So Now I have 2 infraction points. I don't see which rule i broke.

You've been here long enough to know we have a C forum and that C questions go in the C forum. I had to move this thread from Community Center, and thus felt justified in giving you an infraction for Keep It Organized.

If you read the PM that was sent automatically with my reason comment, you'd know this though.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's elegant and simple.

And not tail recursive, so you can't expect the compiler to optimize that into a loop. Recursion for linear problems is generally a bad idea due to the inherent overhead and risk of stack overflow, so I'd call the "elegant" solution unusable for robust code.

Further, there's no significant benefit over a corresponding iterative function. All in all, this isn't a place for recursion outside of the classroom.

Some parts get tricky, it's better to have a drawing to understand it better.

That sentence somewhat contradicts the previous one that the solution is simple. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Unless it was removed during refactoring, there should be the beginnings of such a system that I was working on. But it's not ready yet, and my time is unfortunately very limited, so it may not be finished for a while.

For now just notify us through threads such as this one or send a PM to myself and Dani.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

"better" requires creativity, originality and so on...

Only in situations where creativity, originality, and so on are required. "Better" is subjective, and it's prefectly reasonable to say that a code monkey can get "better" without being more creative or original.

when you are experienced you tend to avoid trials and go strait to results.

When you're experienced, your trials just become that much more complex. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A new node is created. If the node passed in is NULL then replace it. Otherwise, using a temporary pointer, walk to the end of the list and tack on the new node there. Finally, return the node that was passed in, which as far as insert is concerned, is the head of the list.

The key is actually saving the result of insert back to your list head, otherwise you can't pass a null pointer in as the first argument.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but cout and printf is not working.

"Not working" is one of the least helpful descriptions of a problem possible. Please be specific about how it's not working. This probably has nothing to do with your project structure and everything to do with failing to include standard headers in the right place.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There are a number of issues including:

  • The list in main is never updated.
  • Your only reference to the list in insert is lost during the loop.
  • A null list isn't properly accounted for in insert.

Consider the following changes:

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

struct list
{
    int data;
    struct list* next;
};

struct list* insert(struct list* node, int data)
{
    struct list* newnode = malloc(sizeof(struct list));

    if (newnode)
    {
        newnode->data = data;
        newnode->next = NULL;
    }

    if (!node)
    {
        node = newnode;
    }
    else
    {
        struct list* temp = node;

        while (temp->next)
        {
            temp = temp->next;
        }

        temp->next = newnode;
    }

    return node;
}

void printlist(struct list *node)
{
    if (!node)
    {
        printf("empty list\n");
    }

    while (node)
    {
        printf("The list contains %d \n", node->data);
        node = node->next;
    }
}

int main(void)
{
    struct list *temp = NULL;
    int i, n, m;

    printf("ENTER THE NUMBER OF ELEMENTS\n");
    scanf("%d", &n);

    for (i = 0; i < n; i++)
    {
        scanf("%d", &m);
        temp = insert(temp, m);
    }

    printlist(temp);

    return 0;
}
Qwert_1 commented: Could you please explain me how is the insert function working here? :) +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What are you passing as width and stop? So what values do argv[2] and argv[3] have? That's somewhat important in replicating your results. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

An exclusion scanset (the %[^ specifier) won't extract any of the excluded characters, so the stream still contains a comma after HuffOriginal is extracted. The simple answer is this:

sscanf(buffer, "%[^,],%[^\n]", HuffOriginal[i], HuffSymbol[i]);
billkas commented: Thanks! +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

gcc -o test test.c from command line , i am compling with the old gcc compiler right ? so if the code has long long int in there , which isnt supported before c99 , shouldnt i get a compile time error ?

The default mode for gcc is -std=gnu89, which IIRC does include support for a form of long long.

i tried to compile from pelles 's command line using the cc /Ze test.c command i found in here, but it gave me a lot of errors .

Those are all from Kernel32.lib. Pelles C should just work right out of the box, so I'm not sure why you're getting those errors as they're an internal detail. Check your linker settings to ensure that all of the Win32 libraries are included.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Barring the obvious issue of not properly handling the last span of characters unless they're exactly width length, I don't see any problems. I'd do a few things differently, but the way you're doing it is functional.

Can you provide a sample file as well as an invokation string so that we can see what you're seeing?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

POLINK: error: Unresolved external symbol 'WinMain'.

You're trying to compile the project as a Windows application rather than a console application. Windows applications use a different entry point called WinMain. This is an easy one to fix, just change the appropriate setting for your project to build a console application.

somjit{} commented: thanks :) +3
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You don't need the strcat() in this case, just sprintf():

sprintf(f, "N%d", k);

Cue everyone telling you to use std::string instead of C-style strings.

manel1989 commented: 5 +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That tells me exactly nothing. :P

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How general is this intended to be? Because you're looking at essentially a mini-compiler that parses and evaluates mathematical expressions. In other words, it's not exactly a trivial project.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

While I understand the end result you want, I'm not sure what you mean by doing it in a separate class. Can you be more specific?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Be more specific about what parts you want help with. Simply posting your assignment is against Daniweb rules because it implies you want your work done for you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Off the top of my head I want to say that obj.x will use B's copy and A's copy is hidden, but it might be compiled as a syntax error because obj.x is ambiguous. Honestly, I can't recall at the moment which it would be in portable code. :P

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can resolve the name, but my recommendation is to avoid that situation in the first place if possible. Here's how to resolve the name:

int main()
{
    B obj;
    obj.B::x = 123;
    obj.A::x = 456;
    std::cout << obj.A::x;
    return 0;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Unsized arrays are allowed in a class, i believe.

Only as static members, and even then you must define them elsewhere. Otherwise you're looking at an incomplete type, which is allowed...until you need it to be complete (ie. try to instantiate one).

If you can't give your array a size, you should probably be using a vector.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Honestly, I don't have any links anymore since it's all been internalized. However, I would be shocked if you couldn't find some good articles with the search engine of your preference. Alternatively, if you ask a specific question (ideally in a new thread) I can probably answer it. If not, I can do a good job faking an answer. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You want some variant of getch(). However, note that raw input is not portable, so you'll be using something specific either to your compiler or operating system.

This may help, since I don't particularly feel like writing a raw input example for the umpteenth time. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Well, you can't write code to do something that you don't know how to do manually. So I'd direct you to a mathematics resource rather than a programming resource.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Do you know how to do it on paper?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But how does a junior poster in training become one? (I'm just curious)

It's a judgment call amongst the current moderation team. Somebody nominates a member as a moderator to get our attention, then we decide if a new mod is needed and vote on whether to offer an invitation if that's the case.

Anyone can be nominated. However, certain metrics do help in that we can see how the community already views the nominee and how the nominee participates in the community. Metrics that help include post count (ie. activity), solved threads, reputation, and upvote:downvote ratio.

We also (most importantly) look at the nominee's suitability as a moderator, such as maturity, ability to look at situations objectively, and ability to disassociate from emotion when making a decision.

~s.o.s~ commented: Can't put it any better +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Isn't there any way of making it directly initializing with the values given in file.

After a fashion, yes. I'd move the parsing aspects into an input operator for the class that handles all of the grunt work. Then you can simply say f >> s1[i];. As a simple example:

#include <fstream>
#include <iostream>
#include <istream>
#include <ostream>
#include <string>
#include <vector>

class Student {
    std::string name;
    std::string id;
    std::string gender;
    int age;
public:
    Student(std::string name = "", std::string id = "", std::string gender = "", int age = 0) :
        name(name), id(id), gender(gender), age(age)
    {}

    friend std::ostream& operator<<(std::ostream& out, const Student& obj);
    friend std::istream& operator>>(std::istream& in, Student& obj);
};

std::ostream& operator<<(std::ostream& out, const Student& obj)
{
    return out << obj.name << "(" << obj.id << "): " << obj.age << " " << obj.gender;
}

std::istream& operator>>(std::istream& in, Student& obj)
{
    in >> obj.name;
    in >> obj.id;
    in >> obj.gender;
    in >> obj.age;

    return in;
}

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

    if (in) {
        std::vector<Student> students;
        Student temp;

        while (in >> temp) {
            students.push_back(temp);
        }

        for (auto x : students) {
            std::cout << x << '\n';
        }
    }
}

When a class manages its own data internally rather than forcing the calling code to understand it, life is simpler. This is especially important if your class internals might change because then the calling code wouldn't also have to change when that happens.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But the program cannot run? :(

What program? If you're talking about the code I posted, those are just snippets. It's up to you to write the rest and put it together so that it compiles.

I want put other few formule to run the program. There have 10 formula in finicial ratio. So, how to put 10 formule in the program but run one formula.

If the 10 formulae will ever be calculated separately, I'd suggest putting them in their own functions like current_ratio in my previous post. Otherwise, there's no need for separate functions unless the a formula is excessively long or complex and putting it in a function benefits readability. If that's not the case you can throw it all into a single function:

// This is a complete fabrication to exhibit a programming technique.
// Don't expect it to compile as-is or solve your problem as-is.
double financial_ratio()
{
    double ratio =
        current_ratio(some_asset, some_liability) +
        (some_value / some_delta) +
        (another_value / another_delta);

    return ratio / ratio_delta;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My condolences to the new mod. ;)

JorgeM commented: haha, thanks! +0
bradly.spicer commented: Made me giggle xD - Xtrapsp +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Each node is just an anonymous variable that the pointer points to. It seems like your confusion is more about self-referential structures than anything. So let's take a look at a simple linked list:

#include <iostream>

struct node {
    int data;
    node *next;

    node(int data, node *next = nullptr): data(data), next(next) {}
};

int main()
{
    node *head = nullptr;

    for (int i = 0; i < 5; i++) {
        head = new node(i, head);
    }

    for (node *x = head; x != nullptr; x = x->next)  {
        std::cout << x->data << '\n';
    }
}

Your question is about why all of those next pointers don't overwrite each other, but conceptually the list looks like this if you unroll the loop and name each anonymous variable:

#include <iostream>

struct node {
    int data;
    node *next;

    node(int data, node *next = nullptr): data(data), next(next) {}
};

int main()
{
    node *head = nullptr;
    node a{0}, b{1}, c{2}, d{3}, e{4};

    head = &e;
    e.next = &d;
    d.next = &c;
    c.next = &b;
    b.next = &a;

    for (node *x = head; x != nullptr; x = x->next)  {
        std::cout << x->data << '\n';
    }
}

Each pointer points to a unique entity in both cases, the first case simply hides that from you by using anonymous objects versus named variables.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm going to go out on a limb and suggest that the problem is an unlicensed version of the "folder hider" software such that the feature you want isn't available after recent updates.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But, you don't need the sports car.. Make sense? :P

That's where the analogy breaks down, because you do need the classes. If you didn't need them, you wouldn't be using them in the code, right?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are you asking if there's a way to avoid linking with the implementation of a class? If so, that's like asking if you can buy a car without an engine and be able to drive it around normally. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Somehow I suspect you're not providing nearly enough information for us to give you a helpful answer. However, as stated this can be done with a trivial function:

double current_ratio(double asset, double liability)
{
    return asset / liability;
}

That can be extended into a declaration and defnition using two files as well. First the header:

#ifndef CURRENT_RATIO_H

double current_ratio(double asset, double liability);

#endif

Then the implementation file:

#include "current_ratio.h"

double current_ratio(double asset, double liability)
{
    return asset / liability;
}

The third file would likely be your driver that contains the main function, includes the header, and uses the current_ratio function.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Covariance only works within an inheritance hierarchy. What you seem to want is a variant type in general, which can be achieved using Boost::Any or Boost::Variant, depending on your needs.

That said, what exactly are the criteria for selecting the type in your factory? This can change how feasible a solution is without relying on external libraries.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you want a simple and fool proof way for input handling consider taking everything in as strings and running your own checking functions on them for validity.

For standard types provided by the language, end user programmers shouldn't be expected to validate or parse them unless they want. However, simple and fool proof are mutually exclusive in the case of stream I/O. ;) Case in point, the OP's TakeIns are incomplete and the huge variance in I/O needs would find a programmer either extending the class...well, extensively, or dumping it entirely in favor of more common ad hoc approaches.

If I were to write something like this, the back end would almost certainly be based on string input and customized validation that can scale. But I'd also include a caching mechanism that minimizes the single biggst issue with stream I/O and robustness: lookahead.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You could try Daniweb chat for such things. ;) However, I don't think this kind of question is unsuited to a thread, especially since you might get a large number of differing opinions and a very interesting debate out of it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You're not the first to mention that. It's certainly not very intuitive as far as I'm concerned, but Dani makes the final decision. Let's see if she weighs in.