deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Wouldn't it be simpler to defer that prefix algorithm to a separate function that returns a boolean?

for (;;) {
    printf("Please key in the number of passenger >> ");

    if (scanf("%s", &mass_passenger_check) && starts_with(mass_passenger_check, isdigit, 3)) {
        break;
    }
}

Writing such a function is trivial:

int starts_with(const char *s, int (*pred)(int), int n)
{
    while (--n >= 0) {
        if (!*s || !pred(*s++)) {
            return 0;
        }
    }

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

The most greivous error is that arrays in C++ are 0-based and you're treated yours as if it were 1-based. num[5] is not a valid index. Consider this:

#include<iostream>

using namespace std;

int main()
{
    int i,m,num[5];
    cout<<"Enter Integer Values";
    for(int a=0;a<5;a++)
        cin>>num[a];
    for(int j=1;j<5;j++)
    {
        i=1;
        while(num[i]>num[j])
            i=i+1;
        m=num[j];
        for(int k=0;k<=j-i-1;k++)
        {
            num[j-k]=num[j-k-1];
        }
        num[i]=m;
    }

    for (int i = 0; i < 5; i++) {
        cout << num[i] << '\n';
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You seem to be conflating programmer quality with language or platform quality. Once again, both PHP and ASP.NET meet your needs. A shitty programmer will write shitty software regardless of what tools he uses, and conversely a good programmer will write good software regardless of his tools. Strive to be a good programmer, strive to write solid software, and it won't matter much what language or platform you choose.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If either one were conclusively "the best", the other would have died long ago. Both ASP.NET and PHP are a good choice for your stated needs. If you want to do a proper comparison, you'll need to dig down to something far more specfic than "huge amount of users" or "performance and security".

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's certainly frustrating when I'm working with a programmer who clearly has a weak fundamentals, but I don't think "modern" languages (whatever you choose to mean by that) are the only culprit, or even the most prominent culprit. More likely is this wonderful resource we have called the internet, and the fact that one can practically cut and paste their way to a reasonably functional application with little more than a laundry list of Google queries.

It's simple evolution concerning languages that do a lot of the grunt work for you, because software is becoming ever more complex, yet our deadlines for writing it remain short, and the capacity of our brains remains limited.

deltascrow commented: I agree, though I sort of was referring to the detailed libraries given out with the language(s). Though it makes coding easier, new people tend to stop using their minds once they see the libraries. Just saying. :\ +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think i have coded the program correctly but when I try to run it, it doesnt run...

Can you be more specific about what happens when it "doesn't run"? Does the program not start at all? Does it ask you for a filename but then give an error? Does it get past the filename part and loop forever? Does it not loop at all? Did you try to debug your code? We need more information to help you.

Dont write
using namespace std;
Try without it. It worked on my pc. :-D

You need a newer compiler, dude. Yours is non-compliant with standard C++.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd suggest this tutorial as it covers a lot of information, but builds up to it with just enough code to get the job done. It's written in C, but a conversion to C++ is trivial.

Concerning your immediate problem, I notice that you never modify p, even though it being NULL or not is a key component of the algorithm. Assuming p is supposed to be your head node, that means you need something more like this to build the list in reverse:

#include <iostream>

using namespace std;

struct node
{
    int data;
    node *next;
} *p;

int main()
{
    node *tmp;

    cout << "Enter numbers (0 to stop): ";

    while (true)
    {
        int num;

        if (!(cin >> num) || !num) {
            break;
        }

        tmp = new node;
        tmp->data = num;
        tmp->next = p;
        p = tmp;
    }

    // Test the list outside of the creation loop
    for (tmp = p; tmp; tmp = tmp->next) {
        cout << tmp->data << (tmp->next ? "->" : "\n");
    }

    // Ignore list destruction for now
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Welcome. I'm sure you'll find our Java community both willing and adept at helping you reach your goal.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i am very glade to told you that you guys must learn java programing language because i think aproximate one billion devices are running java...

Just because there are ~1 billion devices running Java, that doesn't mean I need to write code for them. Your statement is basically an appeal to popularity, where because sooo many devices use Java, you must learn it. But what if you don't need to learn it, or don't want to learn it?

It's also unconvincing because you only think there are ~1 billion devices running Java. Lack of confidence in listing statistics only makes those statistics look inaccurate or fake, and it reduces your credibility by a substantial amount.

so first of all i recommeded you that you guys get the "The complete Java reference book 2"it is the best book for you guys believe me

I don't believe you. Convince me that this book is the best. :)

if you guys take some interest in java you have a greate future ..

Vague promise of good things to come is also a fallacy: appeal to emotion. You might even call it a red herring because there's no direct connection between knowing Java and a "great future". The irrelevant "great future" is introduced entirely to make learning Java look attractive. It's also somewhat of a post hoc fallacy because there's an implicit assumption that interest in Java is the cause of a "great future".

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

which is better for a noob programmer ? netbeans or jcreator?

While I agree with James as far as learning how things work under the hood first, it's not unreasonable to move quickly into an IDE once you get a handle on it. In that case I'd suggest JCreator as a first IDE because it's simpler (at least it was when I last looked). Once you start getting more serious, then NetBeans begins to shine as one of the better IDEs.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@deceptikon: Have this book on my amazon wish list! Is it really worth the buy, even for a non pro like me?

I think it's worth it, but only if you're not already well versed in classic algorithms and data structures.

Simply download it from a torrent :p

That constitutes copyright violation, is illegal, and as such is also a violation of Daniweb's rules. Please don't encourage illegal behavior.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What is the most efficient way to read a bit at a particular position in a byte?

Amazingly enough, it depends on the bit in question. A general approach to reading any bit neglects tricks for reading specific bits more concisely (ie. using fewer instructions), and thus "faster".

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I've been programming in .NET professionally for almost a decade and I still think of this when people say "CLR". :D

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Adding to what sepp2k said, when you say Text foo, it's as if you said char foo[80]. A typedef represents a type, where the name of the typedef fits in the same place that the variable name would in an actual declaration. It's simpler and more consistent to keep the same declaration syntax rules.

nmakes commented: Hmm... Thank you! :D +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The problem seems to have solved itself, but the answer is largely no. There are two ways to reverse a vote/rep:

  1. The voter must do it from their account by navigating to the post and clicking the vote button a second time.
  2. We go into the database, delete the record, and update any statistics manually.

Obviously #2 is to be avoided, so except in outstanding cases, you're the only one who can reverse your votes on a post.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Will there be any rating score of a thread (quality of the topic in the thread) in the future?

Possibly. :) Technically it's no big thing to add thread ratings, but I'm on the fence as to whether it should be calculated from thread statistics or more of a voting style. There are pros and cons to each approach.

If you'd like to discuss it, feel free to start another thread so as to not derail this one.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Note that I'm adding to happygeek's answers and directing them at geniusvishal.

No, it is not possible. Even administrators (such as myself) cannot see who is downvoting. The system is designed to be anonymous.

It's possible, given that we do store that information in the database. But there's no interface for it yet, and retrieving the information requires a direct database query by Dani (as she's the only one with that kind of access). So for harrassment cases we can track down guilty parties, if necessary. That's only happened once in the entire history of Daniweb though, so I wouldn't be too worried about it. That's also why an admin interface for searching votes is somewhat low on my priority list.

You have contacted them as they, along with the administrators, read this forum. You can also flag individual posts as bad, which will bring those specific issues directly to the attention of the moderating team (flagged posts appear in a closed forum where the mods can review them and take action as necessary).

You're also welcome to send any of us a private message with concerns you may have. The "no help through PM" rule doesn't apply to issues that might require moderator or admin attention. ;)

Yes, the asp.net forum is being moderated.

"Moderated", as pertains to the question may mean "every post is systematically reviewed" as opposed to what actually happens which is more along the lines of "keeping an eye …

geniusvishal commented: Thank You again. By the way DiHydrogen Monoxide is water... :-) +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Traditionally in computer-based fields a degree was mostly useful for your first job. After that your experience and skills would determine marketability, and that's still true more so than in other fields. However, these days a 4 year degree is becoming more and more of a step 1 filter by HR departments. Unless you have a contact on the inside who can recommend you, a degree would help on cold calling.

I have an A.S. degree, but I've been lucky that all of my jobs and offers have been acquired through previous contacts rather than doing foot work. As such, I'm a strong proponent of networking to build a contact list and save yourself the hassle of being just another resume in the stack.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can you post your code?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your code doesn't have any continue logic. Could you post the code that "fails every time" so that we can help you fix it?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

when converting an int or float from a string, if it converts a "0" to a 0, the program sees it as an error.

That's one of the primary reasons why you shouldn't use atoi(). The other reason is that if the string doesn't represent a number, you invoke undefined behavior. I posted an example not to long ago on how to properly use strtol() as a replacement for atoi(): Click Here.

However, since this is C++, I'd favor a stringstream (which includes validation that doesn't affect the result), or C++11's stoi() (which will throw an exception for errors rather than overload the return value).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

By "record" I was thinking more of a structure-based solution. You'd read a line from the flat file, break it down into fields, then populate a structure with validation rules to determine if the line was legit or not. For example, using this test flat file:

12345,Joe,Blow,19,3.1
55326,Jane,Doe,20,4.0
47200,Stu,Bernstein,20,2.5
78309,Foo,McDiddles,19,1.0

You might parse and display it like this:

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

typedef struct student {
    int    id;
    char   first[10];
    char   last[50];
    int    age;
    double gpa;
} student;

int deserialize(const char *s, student *record, char *delim)
{
    char *temp = (char*)malloc(strlen(s) + 1);
    int rc = 0;

    if (temp) {
        char *tok;

        /* make a working copy because strtok modifies the string */
        strcpy(temp, s);

        rc = ((tok = strtok(temp, delim)) != NULL && sscanf(tok, "%d", &record->id) == 1) &&
             ((tok = strtok(NULL, delim)) != NULL && strcpy(record->first, tok)) &&
             ((tok = strtok(NULL, delim)) != NULL && strcpy(record->last, tok)) &&
             ((tok = strtok(NULL, delim)) != NULL && sscanf(tok, "%d", &record->age) == 1) &&
             ((tok = strtok(NULL, delim)) != NULL && sscanf(tok, "%lf", &record->gpa) == 1);

        free(temp);
    }

    return rc;
}

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

    if (in) {
        student records[10];
        char line[BUFSIZ];
        size_t i, n;

        for (n = 0; n < 10 && fgets(line, sizeof line, in); n++) {
            if (!deserialize(line, &records[n], ",")) {
                break;
            }
        }

        for (i = 0; i < n; i++) {
            printf("Student #%d\n", records[i].id);
            printf("\t%s, %s (%d)\n", records[i].last, records[i].first, records[i].age);
            printf("\tGPA: %1.1f\n", records[i].gpa);
        }
    }

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

this code kind of gives me the output i need. is there a better way to do this?

Always start with "working", then work on "better". But aside from tossing those several calls to strtok() into a loop, I'd say you're on the right track. Do you have any concerns about storing the strings in a record?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

that code is a bit more advanced

CSV is a bit more complicated, so the code to handle it must also be more complicated.

what if its just a regular csv file, no quotes.

Let's make one thing clear, when you say CSV you imply a format that includes the following restrictions (based on RFC 4180):

  1. The first line may optionally be a header.
  2. Each record is placed on a separate line.
  3. Each record contains one or more fields separated by a single comma.
  4. Empty fields are represented by two adjacent commas.
  5. Each field may optionally be surrounded by double quotes.
  6. If a field contains a newline, comma, or double quote, then the field must be surrounded by double quotes.
  7. Double quotes inside of a field must be escaped by doubling them (eg. "allowed ""'s inside").

So when you say "regular" CSV, the above is what everyone will assume. In my experience the most common CSV feature that's not included is support for embedded newlines.

You can say "simple" CSV, or CSV "without quoting rules", or even "comma delimited" to make it clear that you only support comma delimiters and none of the special rules. However, this also introduces the restriction that you cannot have embedded commas in a field. In my experience, this is often prohibitive to the point where I prefer pipe characters ('|') for simple delimited files because pipes are less likely to be in a field.

what if …

smith32 commented: that help me understand the CSV file and inspirit to learn CSV file format. Thank you a lot. +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Rather than treat each line as separate and independent, collect them in a record where you can validate each field as it relates to the others. So for line 8 you'd be looking for a name, correct? Digits are a clear case of error when looking for a name, so that would fail the validation check and subsequently cause you to stop reading the file because it's clearly malformed.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Do you know how to find the solution in a graph manually? If not, that's where you start. Understanding both the problem and how to reach a solution to the problem is paramount. You can't write code to do something you don't know how to do.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I guess strtok can read a csv file

Only if there are no embedded delimiters in a field. strtok() isn't smart enough to determine that a field is quoted and ignore the a delimiter if it's inside a quoted field, nor is it smart enough to recognize escaped quotes.

As I mentioned before, you need to take more care in parsing the format, because it's not as simple as splitting on commas. For example:

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

char **split_csv(const char *line, char delim)
{
    char **buf = (char**)malloc(2 * sizeof *buf);
    size_t pos, n = 0, len = 0;
    int inquote = 0;

    if (!buf) {
        return NULL;
    }

    buf[n] = NULL;

    /* Trim leading whitespace on the first field */
    for (pos = 0; line[pos] && line[pos] == ' ' || line[pos] == '\t'; pos++) {
        ++pos;
    }

    for (;; pos++) {
        char ch = line[pos];

        if (!inquote && len == 0 && ch == '"') {
            /* Starting a quoted field */
            inquote = 1;
        }
        else if (inquote && ch == '"') {
            if (line[pos + 1] != '"') {
                /* Terminating a quoted field */
                inquote = 0;

                /* Trim trailing whitespace on the field */
                while (line[pos + 1] && line[pos + 1] == ' ' || line[pos + 1] == '\t') {
                    ++pos;
                }
            }
            else {
                /* The quote was escapted so it doesn't count */
                buf[n] = (char*)realloc(buf[n], (++len + 1) * sizeof *buf[n]);
                buf[n][len - …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So, I wonder if it being described as a zoom problem is an over-simplification

The "zoom problem" description is in reference to desktop browsers. Tablets are a completely different beast, and I would wager that fixing the problem there would involve catering to the tablet browsers in question with conditional HTML/CSS, and possibly even having cases for different tablets due to varying aspect ratio.

I'm not dismissing the problem by any means, I just think solving it is impractical at present given the variance in tablets and installed browsers as well as the very small minority of members using tablets (sorry Davey).

However, if anyone who is having trouble with a tablet wants to reply to this thread or PM me with the make and model of their tablet as well as the browser having a problem, I can compile a list of them and look into how much effort would really be involved.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

if i have an empty char array and I pass it to scanf
will scanf add the nullbye?

You already asked this question and it was already answered: yes.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I seem to be agreeing with deceptikon a lot lately! :-)

I'm very agreeable. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

strtok() doesn't respect CSV quoting rules, and as such it's the wrong solution to your problem. You need to actually parse the CSV format and break it down properly, which means either using a library or writing your own parser (not especially difficult, but not trivial either).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are you trying to store the music file itself as a blob, or are you storing a path for the file and relevant metadata? Because the former isn't recommended and the latter is trivial as long as you have a way of extracting the metadata.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

what is the difference b/t PHP and ASP.net

In what context? There's a world of difference even though they can both solve a similar problem (ie. server side scripting). Your question is like asking what the difference is between a Mac and a PC, it's a very broad topic.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I have to build a programme

Yes, you have to build it. What have you tried so far? What has your research into solving the problem shown you so far? Have you done anything?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

is it necessary to add it all the time?

Yes, because that's the definition of a string. Just because something seems to work at the moment you test it doesn't mean it's correct or guaranteed to work all the time. C is one of those languages that won't help you if you do something stupid, so it's up to you to avoid doing stupid things.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Under certain desktop layouts, typically tablets or rotatable displays, the Community button sits beneath the Hardware & Software button. So that, when a pointer hovers over the Hardware & Software button, the first few items on the dropdown menu is obscured by the Community button sitting below the Hardware & Software button.

Usually that's a zoom problem that's easily corrected, but if it's on a tablet and you don't have control over it, a workaround is to go to the home page where there's a list of all top level forums on the right hand column.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

For example, if someone complained that a link to a compiler was dead, and you realise they are asking this in a thread that is four years old, then it would be understandable to point out what's what regarding the age of the thread, etc...

Daniweb policy is about objectivity; if we can't objectively defend an action, then no action takes place. If the necrobump post is both relevant and not spam then it's acceptable. Who are we to say that a discussion older than N days, weeks, or months can't be continued? If the necrobump post is not relevant or constitutes spam, it gets the axe because in that case the current threads on page 1 take precedence. The problem in my opinion is that bumping a post not already on page 1 will push another post that was on page 1 to page 2. A thread falling to page 2 is the kiss of death, and it's not fair to the author.

I personally think it's an insult to current thread authors to allow valueless necrobumps that might push them to the second page. However, flat out deleting innocent posts that a mod subjectively deems "valueless" could very easily turn a potentially valuable new member off to the community. That's why we specifically focus on relevancy and non-spam as indicators of when to allow a bump.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you're using LPCWSTR in the first place, you should also be using std::wstring rather than std::string. Then you can just use the c_str() method from std::wstring directly. It's certainly possible to convert the latter into the former, but it's fair to say that not having to do a conversion is the better option if you can manage it:

#include <string>
#include <vector>
#include <Windows.h>

namespace strings {
    std::wstring widen(const std::string& s)
    {
        std::vector<wchar_t> buf(MultiByteToWideChar(CP_ACP, 0, s.c_str(), s.size() + 1, 0, 0));

        MultiByteToWideChar(CP_ACP, 0, s.c_str(), s.size() + 1, &buf[0], buf.size());

        return std::wstring(&buf[0]);
    }
}
CodeAngry commented: You should still consider checking s.empty()... and return a std::wstring() directly. +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What have you figured out so far?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I never defined str size, yet it works

It crashes miserably and consistently for me. I guess "works" is a pretty loosely defined term. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

We require proof of effort when helping with homework questions. What have you done so far? Do you know how to calculate the average of N numbers manually? Do you know how to create and populate an array?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm not sure exactly how that should be achieved, but I imagine at least the age of a post should grow larger and bolder as the post grows older.

I like that idea. Perhaps make it stand out by using a bold font and red color after our age threshold. Something to consider.

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

I wasn't going to use paramerterized queries..... I thought it was just an "extra step".

They are an extra step, but a valuable one nonetheless. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Thats another way to read file content.

Assuming that the body of the loop properly checks for and breaks on end of file, sure. However, this loop will likely print the last line of the file twice:

while (inFile.good()) {
    getline(inFile, line);
    cout << line << '\n';
}

The reason is because getline() will reach end of file and do nothing with line, but the output sits between the reaching of a "failure" state and the test for that "failure" state. The obvious fix would be to break on failure:

while (inFile.good()) {
    if (!getline(inFile, line)) {
        break;
    }

    cout << line << '\n';
}

But a C++ convention already exists that does this as the loop condition because it's more concise and says everything that needs to be said without extra fluff:

while (getline(infile, line)) {
    cout << line << '\n';
}

As such, the recommended approach is to ensure that your input mechanism can be called and tested as the loop condition because anything else risks a variation of the classic feof() bug from C.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Nevermind. I try email NXP. May be their compiler support this feature.

That seems best. If there are no definitions anywhere then you may be dealing with a compiler extension where an empty array size defaults to something.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you will, explain what "SpecialCost" is, What a "SqlDbType.Int" is and what is the purpose of the zero in the parentheses

Judging by your questions, I'm guessing you aren't using parameterized queries. The first parameter is the column name of your table. The second is the type of the table, and the third is the maximum length allowed for the value. I didn't know the setup of your table, so I made up a column name: SpecialCost. Since the type of the parameter is a fixed size, the size argument is ignored, but it's still required in the constructor call. So I just use 0 since it's the most obvious dummy default.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

' I need to say spclcost = DBNull.Value. But how do I do that?

You don't do that. You use either spclcost or DBNull.Value when assigning the database parameter. For example:

Dim parameter As New SqlParameter("SpecialCost", SqlDbType.Int, 0)

If IsNumeric(txbSpecialCost.Text) Then
    parameter.Value = Convert.ToInt32(txbSpecialCost.Text)
Else
    parameter.Value = DBNull.Value
End If

Then add the parameter to your SqlCommand object's Parameters collection. spclcost never gets assigned DBNull.Value unless you want to define it as type Object, but that would confuse the intention of the code in my opinion.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So what is the correct syntax to assign DBNull.Value to the variable "spclcost"?

You don't do it that way. If the string is empty when you write to the database, use DBNull.Value instead of spclcost.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

For writting quality code you must use proffesional IDE.

I disagree. It's not the quality of the tools that matter, it's the quality of the programmer.

Octet commented: I couldn't agree with you more. +3