deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Start by writing a function that will replace words in a string and use a small program to test it in the absence of user input. Your program can be broken down into smaller subproblems that are easier to solve and less overwhelming.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

anyone?

You've had two whole days to work on this program, what have you come up with? Daniweb has a homework rule that states you must provide some proof of effort. If you've just been sitting on your butt waiting for a kind soul to give you everything then you deserve a failing grade.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is there a way to change your avatar into an animated avatar?

No. When you upload an avatar, we resize it internally to ensure that it's 80x80, and the method we use to do that only returns the first frame of an animated image.

I have seen a few avatars that are animated... Know how to upload one?

Most likely you've seen avatars that were grandfathered in during the migration from vBulletin to the current system. That would have side steped our upload process, but it doesn't help you now because the only way to get an animated avatar if you didn't already have one would be to edit the database manually.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

toMakeFood doesn't exist because everywhere you have a declaration of it, you're saying "defined elsewhere" due to the extern keyword. Add an includes.c file with this:

bool toMakeFood = false;

And don't forget to link that file in with the rest. The header will provide multiple delcarations while the .c file will provide a single definition. On a side note, I strongly suspect you're compiling as C because bool and true/false require the inclusion of the stdbool.h header.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I dont use memcpy often

As well you shouldn't. memcpy() is a very low level function that was inherited from C. The problem with memcpy() in C++ is that it doesn't respect class structure or construction/destruction, so unless you have what is called a POD type, use of memcpy() is undefined. My usual recommendation is to forget memcpy() exists unless your code is C compatible.

The usual shallow copying problems present in C were also inherited, such that if you copy a pointer, only the address gets copied and not whatever the pointer points to. That results in an alias that, when unintended, wreaks havoc on memory.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

To do this, you have to use Win32 (Windows API).

Um...to determine the OS you need to use the Windows API? Doesn't that presume that the OS is Windows and then you're just drilling down to the exact version? ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

p_array is a pointer. When you use the subscript operator, that pointer is dereferenced. In other words p_array[index] is functionally identical to *(p_array + index). Now, when you dereference p_array, the result is also a pointer, specifically a pointer to char. So this line is correct because the %s specifier of printf() expects a pointer to char:

printf("%s\n", p_array[index]);

If you further dereference the pointer, you get a char value (not a pointer). The reason you're getting an access violation is because printf() treats that value as an address, because you told it using the %s specifier that you were providing a valid address in the form of a pointer. In other words, you lied to printf(). ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

deceptikon: thanks for that, but i'm unable to match my SOURCE[8] to the const char *src you have used.

It was an example only, I'm not doing your work for you. You'll obviously need to adjust the algorithm to suit your source and destination arrays.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can u help me?

Yes.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Somehow I get the impression that he wants numeric values rather than strings. In that case it would be necessary to either convert the string to a number or build the number directly. For example:

#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>

int digit_value(char ch)
{
    const std::string digits = "0123456789abcdef";
    std::string::const_iterator it = std::find(digits.begin(), digits.end(), ch);

    if (it == digits.end())
        return -1;

    return it - digits.begin();
}

int main()
{
    const char *src = "39 04 7d";

    while (*src) {
        if (isspace(*src)) {
            ++src;
            continue;
        }

        unsigned char value = 0;

        value = digit_value(*src++);
        value = 16 * value + digit_value(*src++);

        std::cout<< (int)value <<'\n';
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Debugger shows this as 1515804759 in Decimal. that is when 5958595a taken as a whole.
why doesn't it show 87888990 like when they are take separately?

Because eax is being interpreted as an integer value instead of an array, so all four bytes are a single entity totaling to 1515804759 rather than separate entities {87,88,89,90}.

Why is it shown as 5a,59,58,57 rather than 57,58........ ? (because W=57 which comes first)

Endianness

and why is it 5A after the 59 in hex? (I know that 10 is A,11 is B etc..... but not this)

Um...what? You know that A comes after 9, so how is 5a after 59 confusing? The rules of the positional numbering system don't change just because there are more significant digits present. The jump to 60 doesn't happen until after F, because hexadecimal has 16 distinct values per digit place: 59, 5a, 5b, 5c, 5d, 5e, 5f, 60.

It seems like you're stuck in a decimal mindset. The only reason 10 comes after 9 in decimal is because there aren't are only ten values that can be represented by a single digit: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. If you add more values, the need for 10 is delayed. If you remove values (such as in octal or binary) then the need for 10 is accelerated. If you think about 10 being the value that happens when you run out of unique single …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Oh and by the way, is it okay to post in purple? Like i just did now?

It's okay, but you're technically not posting "in purple". You're posting with heading tags, which may change their look and feel to be something other than purple. If that ever happens, full posts using heading tags could become unreadable.

Just an FYI, using formatting for purposes other than intended could be counterproductive as the site evolves. We've had issues with that before under vBulletin and code tags for plain text. Dani changed the way things worked and out workaround suddenly broke. ;)

If it is not there, that should be a new site feature :)

It might be tricky to break things down that way, and we try to avoid complex database queries for performance reasons. It's also something of a balancing act to provide enough information to be useful without making people uncomfortable about the easily accessible public information concerning their activity.

However, with that said, if you're interested in specific members you can jump into their public profile and see more detailed stats.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I thought Visual studio 2010 compiler is not open source therefore I won't be able to find thoses files there

These are template classes. Without getting too much into it, due to the way templates are implemented, it's drastically more efficient to keep all of the code together rather than separating declarations and definitions. So template classes are nearly always implemented fully in the header file. Provided the header is actually stored as a viewable file, you can look at the code.

Isn't 'iostream' a part of the c++ library? why do some people call the <iostream> a library, not a file of the standard libarary?

Because everyone knows what you mean when you say the iostream library, there's no ambiguity. Why waste time with a pedantic description when there's no need? There may also be a historical reason, where there were originally many different libraries (of which iostream was one), and they were basically collected into the current "standard" library.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is actualy code different for each OS but the functionalty is the same?

The code is different for each compiler, even compilers on the same OS. But the functionality is defined by a standard rules document that all compilers must adhere to.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

1.If cin and cout objects are in the 'iostream' , why do we need to declare it again using 'std' ?

<iostream> is the header that contains declarations. Without those declarations your compiler doesn't know that the names you use exist. The names themselves are declared within a namespace to avoid collision with other libraries.

Headers and namespaces are not used for the same purpose. In this case you're "declaring" namespace std to save you the trouble of constantly using the fully qualified name each time. Otherwise you'd end up typing std::cout instead of just cout.

2.are cout,cin,cerr,clog the only ones in the iostream?

Yes (including wide counterparts). But keep in mind that there's a metric shit ton of scaffolding behind those objects, which you'll find in headers such as <ios>, <istream>, and <ostream>. <iostream> is conceptually just the header that defines the objects cout, cin, cerr, and clog. But those objects have types which are defined in other headers.

The <iostream> header can be as little as this:

#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>

namespace std {
    extern istream cin;
    extern ostream cout;
    extern ostream cerr;
    extern ostream clog;

    extern wistream wcin;
    extern wostream wcout;
    extern wostream wcerr;
    extern wostream wclog;
}

3.under which categories do cin,cout and iostream fall? (library,object etc..)

cin and cout are objects in the standard I/O library.

4.can we use the same iostream for both linux and windows? how come?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The logic for sorting with string keys is no different than with numeric keys. The only difference is in the comparison, where with string keys you cannot use relational operators. Instead, compare with strcmp():

if (strcmp(a->name, b->name) < 0) {
    /* a->name is lexicographically smaller than b->name */
    ...
}

This is as opposed to the numeric way of just comparing directly:

if (a->id < b->id) {
    /* a->id is numerically smaller than b->id */
    ...
}

Other than that, your sorting algorithm shouldn't change unless you also move around the data (in which case some variation of strcpy() may be needed). But since you're already storing these records in structures, you can just copy the structure instances and all will be well.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The comparison delegate returns an integer denoting the relation between the two objects: 0 for equal, -1 if x is "smaller", and +1 if x is "larger". So it would be more like this:

Private Function SortMyList(ByVal x As MyType, ByVal y As MyType) As Integer
    Dim tsX As TimeSpan = x.dEnd.Subtract(x.dStart)
    Dim tsY As TimeSpan = y.dEnd.Subtract(y.dStart)

    If tsX < tsY Then
        Return -1
    ElseIf tsX > tsY Then
        Return 1
    Else
        Return 0
    End If
End Function

Assuming this is how you want to compare the timespans, of course.

Begginnerdev commented: Thanks Deceptikon! +6
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm afraid it doesn't work. :(

Pname will not work. That's a given, so remove that variable entirely; you can't expect it to represent a wide string. Does your log file still contain just "A" when you use fwprintf() to write section->name?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If char could represent the same thing as wchar_t then there wouldn't be two different types of characters. You have a wide string, and thus you need to either convert it to a narrow string iff you're sure that the narrow string can represent it, or properly display the wide string as a wide string:

fwprintf(fp, L"%s\n", str);
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is this a question about the DateTimePicker or about MySQL? If it's the former then the control has a Value property that gives you the stored DateTime object. You can then get the long format as a string and save it to MySQL:

Dim longdate As String = dateTimePicker1.Value.ToLongDateString()

' Save longdate to MySQL
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So it looks like you're not actually doing a full merge sort, you're just merging together three arrays that are already sorted. Really the only tricky part of this is taking what you know about merging two arrays and extending it into three. Here's a two way merge:

int dst[size * 2], n = 0;

while (i < size && j < size) {
    if (a[i] <= b[j])
        dst[n++] = a[i++];
    else
        dst[n++] = b[j++];
}

while (i < size) dst[n++] = a[i++];
while (j < size) dst[n++] = b[j++];

I'll let you take a shot at doing the three way merge, but there are three steps:

  1. Find the smallest item from the three arrays until one of them is exhausted.
  2. Perform a two way merge on the remaining two arrays until one of them is exhausted.
  3. Exhaust the remaining array, if there are still items.

That means you're essentially taking a two way merge and adding a preliminary three way merge until there are two arrays left. So something like this:

while (i < size && j < size && k < size) {
    if (a[i] <= b[j] && a[i] <= c[k])
        dst[n++] = a[i++];
    else if (b[j] <= a[i] && b[j] < c[k])
        dst[n++] = b[j++];
    else
        dst[n++] = c[k++];
}

After that it's a simple matter to determine which array was exhausted and perform a two way merge on the remaining two arrays.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Still a pretty high learning curve for an experiment.

Assuming you'd need to learn how to do the conversion. ;)

I can't see any other code being cost effective in terms of time spent for insignificant or even no gain.

I agree completely. While I can't confidently say one way or another without confirmation from the OP, this whole thread strikes me as excessive focus on performance where there's no real benefit.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's very hard to write code that ends up more efficient than the built-in codes when you're doing conversions.

Actually, it's pretty easy unless you have the same goal of being a general conversion. If you can make assumptions about either the source or destination value you can optimize by avoiding work that the more general algorithm has to do. Often that's exactly what happens when replacing standard library code with ad hoc code for performance reasons.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can anyone link me to a moderator's profile? need to ask them about something personal.

My profile.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't think 7 seconds is outrageous for almost 13 million runs of that loop. Do you have a reason for increasing the speed or is it just premature optimization?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Unfortunately this isn't the kind of variation that scanf() is designed to handle gracefully. What's happening is scanf() is detecting the sentinel character before saving any characters for a field, thus an empty field denotes failure to perform the conversion for the scanset.

You'll need to check for two adjacent commas outside of scanf() and recognize that as a blank field, then clean up the source stream such that scanf() doesn't fail to match the string. For example using sscanf() (such as if you're pulling the line first with fgets()):

#include <stdio.h>

int main()
{
    const char *src = 
        "DET,1420065,ES,427,VIAJES EL CORTE INGLES S.A.,"
        "C/MAYOR 68,ALCANTARILLA,30820,MURCIA,,968895895,"
        "968893770,,A28229813,N";
    char field[1024];
    size_t pos = 0, n = 0;

    while (sscanf(src + pos, "%1023[^,\n]%*c%n", field, &n) == 1) {
        printf("'%s'\n", field);

        pos += n;

        if (src[pos] == ',') {
            puts("Blank field");
            ++pos;
        }
    }

    return 0;
}

And another using the slightly more awkward (in my opinion) get/unget method if you're reading directly using fscanf() or scanf():

#include <stdio.h>

int main()
{
    char field[1024];
    size_t pos = 0, n = 0;
    int ch;

    while (scanf("%1023[^,\n]%*c", field) == 1) {
        printf("'%s'\n", field);

        ch = getc(stdin);

        if (ch != ',' && ch != '\n')
            ungetc(ch, stdin);
        else
            puts("Blank field");
    }

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

which says 'main' must return 'int'.

So return int instead of void. Seriously, use some common sense; these errors aren't exactly being cryptic. I'd explain why void main is wrong, but if your compiler is rejecting it outright then knowing would only be academic. So if you're interested, just search Google for "void main wrong".

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

so what should i do about line 10

Fix line 8.

but at line 102 it is saying 102 C++ forbids comparison between pointer and integer..

That's basically the same thing I said. i is an int and numemps is an array. You can't compare the two because it's not meaningful. Change numemps to an int just like in print_unluckies(); you clearly know how it's supposed to work because you've done it correctly in another function.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Line 10: Often if the line itself is fine, look at previous lines. In this case you neglected to terminate the previous function prototype with a semicolon. The error wasn't detected until line 10, where it caused the compiler to puke.

Line 102: numemps is an array, but you compare it with an int. The two types are not compatible.

Line 115: i was never declared. Line 115 should look exactly like line 102. The error from line 102 won't occur because in this function, numemps is just an int and not an array.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Most likely what you wanted was this:

data[i] = data[i] + m.data[i];

Since the error suggests you don't overload the subscript operator to get the contents of data, you need to touch m's copy of data directly.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i need computer programming code picture for my work

Do you regularly ask other people to do your work? If so, I'm greatly relieved that you're not one of my coworkers.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Judicious use of variable scoping can take care of that. Note how in the following code I've moved variable definitions to the smallest scope possible. I also initialized time to 0, adjusted your variable names to be more consistent/conventional, removed unnecessaries and tightened things up a bit:

#include <fstream>
#include <iostream>
#include <string>

using namespace std;

int main()
{
    ifstream inFile("test.txt"); 

    if (inFile) {
        string journeyName;

        while (getline(inFile, journeyName)) {
            if (journeyName.empty())
                continue; // Discard empty lines

            int nChanges = -1;

            if (!(inFile>> nChanges)) {
                cerr<<"Invalid file format\n";
                return EXIT_FAILURE;
            }

            double time = 0; // Get your ass in gear soldier!

            for (int i = 0; i <= nChanges; ++i) {
                double length, speed;

                if (!(inFile>> length >> speed)) {
                    cerr<<"Invalid file format\n";
                    return EXIT_FAILURE;
                }

                time += (length / speed * 60);
            }

            cout<<"Travel time for "<< journeyName <<": "<< time <<'\n'<<endl;
        }
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are we going to get a new Christmas theme for the site?

Sounds like a hassle, both technically and in dealing with complaints from people who don't celebrate Christmas and are mad that we didn't come up with a skin just for them. ;)

So it's like good old theme - never to be changed?

Actually, it changes almost daily to keep up with SEO and usability demands. Most people just never notice because the majority of changes are small.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That's not a bad guess, but the assumption there is that SREC is its own type, so:

SREC grades[500];

No doubt you know how to declare simple integer variables:

int field;
int size;

Now the only problem is wrapping those three into a structure.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Start easier. Can you define an array of 500 SREC objects?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are you using multiple inheritance?

Off the top of my head I don't recall if the C++ standard requires the base and derived object address to be the same for single inheritance, but it simply cannot be for multiple inheritance. There's no way to organize the structure of the object to make that happen. If you're using single inheritance then my gut reaction is to say that the addresses are implementation-dependent and you can't depend on them being the same.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are you talking about just displaying a picture any way that works, or actually rendering the picture using C++? The former is vastly simpler; you can just start the process of a picture viewer and pass in the location of the picture to open it. The latter is quite a bit harder and not recommended.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Possible, but not directly. The two options are basically to convert the number to a string and index that, or write a function that separates the number arithmetically and returns the digit at the selected index.

Edit:

Just for giggles, here's a fun example. :)

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

class CoolInt {
public:
    CoolInt(int value, int base = 10)
        : _value(value), _negative(value < 0)
    {
        if (value == 0)
            _digits.push_back(0);
        else {
            value = abs(value);

            while (value) {
                _digits.push_back(value % base);
                value /= base;
            }

            std::reverse(_digits.begin(), _digits.end());
        }
    }

    operator int() const { return _value; }
    int operator[](unsigned index) { return _digits.at(index); }

    bool negative() const { return _negative; }
    int size() const { return _digits.size(); }
private:
    std::vector<int> _digits;
    int _value;
    bool _negative;
};

int main()
{
    CoolInt x(12345);

    std::cout<<"x is "<< (x.negative() ? "negative" : "positive") <<'\n';

    for (int i = 0; i < x.size(); ++i)
        std::cout<< x[i] <<'\n';
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Have you read Beej's guide to socket programming?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That's by design. The button goes away to ensure that you don't click it again (and thus create a duplicate post) while the submit code is running.

Just be patient, it should finish in a few moments at most and then refresh to show your new post. Sometimes server load causes things to run more slowly than we'd like, but I haven't ever seen replies take more than about 5 seconds to finish.

If you're getting really long wait times, please let us know.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

All the time I misunderstood the words? >_<

Seems like it. Better here than in a professional setting though, right? That's happened to me an it's mighty embarrassing.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@NP-complete, the word inclusive in pseudo code means you do not include the value in your range.

Actually, it's the other way around. Exclusive means that an end of a range is not included and inclusive means that an end of a range is included. The square bracket means inclusive and the paren means exclusive, so:

[a,b] - Fully inclusive, closed
(a,b) - Fully exclusive, open
[a,b) - Half open, excludes b
(a,b] - Half open, excludes a

Or in other terms, [a] represents the set {a} while (a) represents an empty set {}.

What I said means [1, array_size).

What you said means [1,array_size], which is congruent with the usual pseudocode interpretation. If what you meant was a half open range then it would be closer to:

for each index starting from 1 up to array size - 1

If it is exclusive, it means the value will be included in the range.

I find your explanation hilarous given that include and exclude are opposites. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Those characters are interpreted as HTML. Wrap the code in <pre> or <code> tags and replace those characters with their HTML escape codes if necessary (ie. &lt; and &gt;).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Something like this comes to mind as a first attempt:

#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>

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

    if (in) {
        std::string header;

        while (getline(in, header)) {
            if (header.empty())
                continue; // Discard empty lines

            int changes = -1;

            if (!(in>> changes)) {
                std::cerr<<"Invalid file format\n";
                return EXIT_FAILURE;
            }

            for (int i = 0; i <= changes; ++i) {
                int distance, speed;

                if (!(in>> distance >> speed)) {
                    std::cerr<<"Invalid file format\n";
                    return EXIT_FAILURE;
                }

                std::cout<< header <<": ("<< distance <<','<< speed <<")\n";
            }

            std::cout<<'\n';
        }
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's easy to perceive rudeness from someone who's trying to help, especially if they tend to cut through the bullshit and tell things like they are. If you think someone is really acting out, please report the post so that a moderator can deal with it. Creating a thread like this just comes off as childish and petty.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Finally, you might want to consider using std::copy as an alternative to memcpy, the syntax is nicer, there's some kind of type-safety in there and I don't think that there's any real efficiency difference between them. std::copy can actually be faster in some circumstance

I'd be shocked if std::copy() were more efficient when copying non-POD types because it guarantees that constructors are called and all the nifty stuff that makes C++ work happens. For built in and POD types the compiler will likely optimize to the point of being competitive with memcpy() if not equal to memcpy(), but I have trouble believing that it could ever be faster. memcpy() just blindly copies bytes, usually in the most efficient way possible for the platform. The definition of std::copy() isn't conducive for the optimizations that memcpy() is capable of.

What's really terrifying is that memcpy() on non-POD types:

  1. Doesn't call constructors.
  2. Doesn't respect the structure of class hierarchies.
  3. Is technically undefined behavior.

Therefore, use of memcpy() is considered a bug for all but built in and POD types. So you kind of ended up at the same suggestion I'd make, but for different reasons. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

well I didnt give it a value

Bingo. So the actual value it has is whatever random garbage was in that memory location. Chances are extremely good that you're indexing the array out of bounds.

I just thought that num would be the numbers I am reading from the file.

That makes no sense at all. num is used to index the list array. It's the array that holds the numbers you're reading from file, so I'd expect something like this:

int num = 0;

// Read up to 50 numbers from the file
while (num < 50 && infile >> list[num])
    ++num;

// Display the read numbers
for (int i = 0; i < num; ++i)
    cout<< list[i] <<'\n';
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What are these variants?

They're intuitively named, like B+Tree or B*Tree. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What's the value of num?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If m is even, during splitting, we can choose to keep an extra key in either of the nodes right?

Of course.

And the minimum number of keys in a non-root node would be floor((m-1)/2). Correct?

That depends entirely on the variant of a B-Tree you're using. There's more than one, and the defining characteristic is often the amount of minimum/maximum fillage.