deceptikon 1,790 Code Sniper Team Colleague Featured Poster

wordCount() is ruining the string for later processing. Always remember that strtok() modifies the string by writing '\0' at appropriate places. What about merging the two tasks of counting words and saving them to the array?

#include <iostream>
#include <cstring>

using namespace std;

namespace
{
    const int MAX = 100;
    const int LEN = 100;
    const char* fmt = ".,? ;";
}

int main()
{
    char strWords[MAX][LEN];
    char str[LEN];
    
    cout << "Enter a string: ";
    cin.getline(str, LEN);
    
    int count = 0;
    
    for (char *p = strtok(str, fmt); count < MAX && p; p = strtok(0, fmt))
    {
        strcpy(strWords[count++], p);
    }
    
    cout << "No of words = " << count << endl;
    
    for (int i = 0; i < count; i++)
    {
        cout << strWords[i] << endl;
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The C++ runtime eventually has to call your main(), but there's stuff that needs to be done both before and after. Judging by the name, you're using a Microsoft compiler. If you have the CRT sources then look for crt0.c, it's a small source file that does the runtime initialization.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

In your honest opinion, employee, employer, etc., do you think it matters what college one obtains a degree in Information Technology from when it comes to high amounts of competition?

Realistically, it can matter. Most of the time it only matters that you have a degree, and in IT related fields that's usually only for your first job. Every job beyond that will probably care more about your experience than your education. But it all depends on the employer.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

When you say ch=i++[s]; it means ch=(i++)[s]; , but when you say ch=++i[s]; it means ch=++(i[s]); . It's totally confusing because intuition says it should be ch=(++i)[s]; . But that's where the '!' is coming from. i is 3 at that point, and the next character after ' ' in ASCII is '!'.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

%s prints the whole string. If the starting point for the string steps ahead by one character each iteration, you basically chop off the first character each time.

char const* x = "Alice";

printf("%s", x); // "Alice"
++x;
printf("%s", x); // "lice"
++x;
printf("%s", x); // "ice"
++x;
printf("%s", x); // "ice"
++x;
printf("%s", x); // "ce"
++x;
printf("%s", x); // "e"

By the way, this line:

*x=x[n];

is very bad. x is a pointer to a string literal, and string literals are not allowed to be modified. But that statement tries to overwrite the first character of the string literal with the last.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The for loop is completely nonsensical. It's like this:

for (initialization; condition; increment)
{
    body
}

Where the roughly analogous while loop is:

initialization

while (condition)
{
    body
    increment
}

So your loop, for(i<=5&&i>=-1;++i;i>0) printf("%u",i); would look something like this while loop:

i <= 5 && i >= 1;

while (++i)
{
    printf("%u", i);
    i > 0;
}

Doesn't make much sense, does it?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The text of a macro argument is used, not the value of the variable. So after expansion the statement is:

int i = ++x * ++x;

On top of being undefined behavior, that's probably not the logic you intended. Any expressions with side effects should be avoided as macro arguments:

++x;

int i = SQ(x);
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It all looks good to me. To answer G, your answer for D will help. Just remember that it's a nested loop and the solution will be apparent. :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can build the query string dynamically. It all depends on how the POST data is organized, but assuming everything in $_POST corresponds directly to table column names and values, here's an example:

$columns = array();

foreach ($_POST as $key => $value)
{
    $columns[$key] = "'" . mysql_real_escape_string($value) . "'";
}

mysql_query('INSERT INTO tablename (' . implode(',', array_keys($columns)) . ') VALUES (' . implode(',', $columns) . ')');
asprin commented: Looks fine. +1
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What i asked is, how to write the the code, which don't give a undefined behavior still giving the correct output for this exact question.

The undefined behavior comes from modifying the same variable more than once in the same expression. To get rid of undefined behavior, first figure out what output you want, then break up the expression to do it. In the first post on this thread, the first code snippet has undefined behavior and the second code snippet is the right way to fix it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why not use String.Replace()?

string NewDate = Date.Replace(".", string.Empty);
Philippe.Lahaie commented: agreed, and made me laugh! +2