deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A busy wait loop will task the CPU while putting the thread to sleep will not. If you need a short sleep to let the connection close completely then Thread.Sleep() is the way to do it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What are the advantages of a single pointer? Answer that and then you have the answer for double, triple, quadruple, etc. pointers.

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

Hypotheticaly, if you have a large object that is needed almost everwhere within a program and this object is used for accessing data. Is it better to pass the object by referance into each function that needs it, or to make the object static?

Hypothetically, I'd question whether that large object is really needed everywhere or if it's just a lazy design. There's probably a better way to organize the program where that object's scope is limited or need for the object removed entirely.

On the other hand, global variables are one of those things that are easily abused, and that's why the advice is to avoid them. But when they really do provide the best option, they should be used carefully. Obfuscating things to avoid global variables isn't a better solution in my opinion.

Your CentralAssetManager might be best implemented as a singleton. It's still global, but much more controlled than just some random variable.

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

This is a stupid question, but taking my example above, are you making sure that $foo contains the value you expect?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Close, don't forget 0. It makes all the difference. :) It's also possible to use a trick with strings and avoid typing out the whole array:

char const* hex = "0123456789ABCDEF";

// get the least significant digit in hex
char digit = hex[value % 16];
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That's because you are new and haven't developed the keen Spidey Programming sense yet. It'll come...

How long does that take? Because I've been programming for well over 10 years and still have a dull Spidey sense. :D

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If the checkbox should be checked, add checked="checked" to the input tag attributes:

<input type="checkbox" name="foo" value="1" <?= $foo ? 'checked="checked"' : '' ?> >
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

They're hexadecimal. 0x is a common prefix for hexadecimal. You'll also see a suffix of h. But the telltale sign is letters.

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 compiler is right. Sports is a class name, and you can't use it to call a non-static method. To call getName() you first need to create an object of the Sports class.

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

arrays decay into pointers..

Only most of the time. A common misconception is that arrays are equivalent to pointers because of that behavior.

If we consider..
int a[20];
'a' represent the starting address of the array which indeed means that it is a pointer..

http://www.torek.net/torek/c/pa.html

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is this correct?

Yes, that's the biggest reason why vectors are recommended over arrays.

If this is correct even arrays size in c can be manipulated using realloc() function..

Arrays and pointers are different. realloc() only works with pointers that were previously allocated memory by malloc(), calloc(), or realloc(). Arrays have a compile time fixed size.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are arrays and vectors the same?

No.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

when they click the link is the form data submitted?

No. At its simplest you would put a submit input field in the form. Then when the submit button is clicked, the form data is posted:

<form name="passvalue" action="myscript.php" method="POST">
    <input type="hidden" name="title" value="<?php echo $title ?>" />
    <input type="submit" name="submit" value="Click to Submit" />
</form>
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I saw this example while i am searching about vectors..

vector<double> student_marks;
    // no size specified: vector contains
    // no elements
 
int num_students;
cout << "Number of students: " << flush;
cin >> num_students;
 
student_marks.resize (num_students);
 
for (vector<double>::size_type i = 0; i < num_students; i++)
{
    cout << "Enter marks for student #" << i+1 
         << ": " << flush;
    cin >> student_marks[i];
}

cant we use

for (int i = 0; i < num_students; i++)

instead of

for (vector<double>::size_type i = 0; i < num_students; i++)

thanks in advance

num_students is an int, so you shouldn't use vector<double>::size_type. size_type is an unsigned type, and int is signed. It's not usually a good idea to mix signed and unsigned types.

If you use the size of the vector as a loop condition instead, then size_type would be best:

for (vector<double>::size_type i = 0; i < student_marks.size(); i++)
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Well, I believe that author from that link should preface his work with a detailed explanation of compiler architecture and structure optimization. He is using a poorly optimized structure as follows:

struct my_buf {
  char buff_type;
  size_t size;
  char buffer[50];
};

He will have three bytes of padding between buff_type and size not to mention additional padding at the end of buffer. Since size is an unsigned int which must be 4 byte aligned, it can only appear at byte boundaries that are multiples of 4. Thus, the reason for the 3 bytes of padding. In this example it would definitely not be wise to use memcmp because of all the padding.

But let's look at the OP's structure:

struct {
 int score;
char name1[20];
} lol[50];

The above example has no padding since score starts at the very beginning of the structure and starts on a byte boundary which is a multiple of four. Also, note that name1 size is a multiple of 4. Thus no padding is needed and using memcmp is perfectly acceptable.

But let us just say that we are stuck with that ugly structure. How could we use memcmp with that structure which contains padding? Well, the MS compiler would use pragma commands. For example,

#pragma pack(push)  /* push current alignment to stack */
#pragma pack(1)     /* set alignment to 1 byte boundary */

As indicated the current alignment is pushed to the stack and we are now using 1 byte boundaries. Thus, eliminating all the packing in …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How are you submitting the form?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you're not getting any errors but the image is broken, the URL is probably wrong. First make sure that $pic represents a file name that exists in the site_images directory, then make sure that that whole URL is accessible to the page as written.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm sorry, but that doesn't help at all. If you don't have any hard requirements that can be translated into steps for a computer to execute, thinking some up is where you should start. Right now it sounds like all you have is the vague concept of 'hey, I should write a program that does an antisaccade task'.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

and even is it that turbo c supports less graphics other than the other softwares?

Sorry, I'm done with this thread. There must be a language barrier, because you don't seem to understand a thing I'm saying.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't have any tips because you didn't explain what the program is supposed to do. It's not safe to assume that anyone here knows what an anti-saccade task is, much less infer your program's requirements from that even if they did.

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

so its not preferable to use the odd combinations..

...

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

what's the difference of using turbo c and the other softwares for writing the program?

Compilers are designed to target an OS. If the OS dies or is too outdated to be useful then the compiler that targets it shares the same fate. Turbo C was designed for MS-DOS. If you're not using MS-DOS, you shouldn't use Turbo C.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Then its preferrable to use other softwares other than turbo c?

I don't see how we're back to this, but yes, it's preferable to forget Turbo C exists.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is this a predefined one ?

I don't know what you mean by 'predefined', but that's just an example of how mixing two different heaps will blow up in your face. It's an empirical proof of this statement: 'The data structure used to store and manage allocated memory might be different between malloc()/free() and new/delete. If you mix them, the pointer might be valid with one but not the other and your program will probably crash.'

where did u use malloc or new in this code?

Nowhere, because they weren't relevant to the point of the code.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

are they portable?

No less portable than Turbo C.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

the one u explained is a predefined one or just an example?

I don't understand the question.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is it an old idea to compile and run c programs on turbo c?

Yes, by about 15 years. Visual C++ is freely available, Code::Blocks comes with a recent gcc build, and I hear Pelles C is good too. There are more, but those are the three most common recommendations.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

ok the only reason is it may cause problem when it is used in any other compiler or version

There are two big reasons:

  1. The new operator calls constructors and the delete operator calls destructors. malloc() and free() only work with raw memory. So if you use malloc() to allocate objects with constructors the constructors will not be called; this will probably crash your program. Likewise if you use new to allocate objects with destructors and free() to deallocate them, the destructors won't be called; this will probably cause resource leaks.
  2. The data structure used to store and manage allocated memory might be different between malloc()/free() and new/delete. If you mix them, the pointer might be valid with one but not the other and your program will probably crash.

    For example, on a Windows compiler the heap might be created with HeapCreate() instead of GetProcessHeap() and malloc()/free() could use a different heap object than new/delete like this:

    #include <Windows.h>
    
    class memory_manager
    {
    public:
        memory_manager(): _heap(HeapCreate(0, 0, 0)) { }
        ~memory_manager() { HeapDestroy(_heap); }
    
        void *alloc(size_t bytes) { return HeapAlloc(_heap, 0, bytes); }
        void dealloc(void* p) { HeapFree(_heap, 0, p); }
    private:
        HANDLE _heap;
    };
    
    int main(void)
    {
        memory_manager new_manager;
        memory_manager malloc_manager;
    
        void* p = new_manager.alloc(1);
    
        malloc_manager.dealloc(p); // Boom!
    }
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The solution to your problem is to use the memcmp function as a comparison of your structures. I do realize that this is somewhat of an unorthodox solution. But it does work. I did put together some proof of concept code to verify that it does in fact work. Unfortunately, I can't post any sample code. Otherwise I'll get more "demerits" from a mod.

But to reiterate, using memcmp will resolve your problem.

Good luck.

Padding can wreak havoc on that solution. See this link for details.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

May I suggest the OpenPOP library? I've used it in several projects and haven't had any problems yet.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What I've come up with for the last one is n * log n which would be a Big O notation of O(n(log n)).

That's what I was thinking of.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

when you say it "'must' have been written", are you too sure about it, or are you not too sure about it.

I'm sure enough because that's the only way it could have happened.

If you are sure, could you possible give an example of the compiler/assembler written in machine language

No, because that's way back when it would have been written using punch cards or some even older format. We're talking about primordial stuff happening in the 1940s/1950s here. It's not exactly well documented, but you could search Google.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But if the process is undefined, how does it actually manage to swap the elements in question (i can swap the elements successfully using this statement with gcc compiler).

Undefined doesn't mean it won't work. Undefined also doesn't mean it *will* work. Undefined means anything can happen, and that's not a good trait to have in a program. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Any workaround this?

Exclude any fields that don't correspond to a database column. If it were me, I'd store the columns in an array or object and just iterate over them and store anything in $_POST that matches:

$columns = array('column1', 'column2', 'column3', 'column4');
$fields = array();

foreach ($_POST as $key => $value)
{
    // Only use fields that are known to the database
    if (isset($columns[$key]))
    {
        $fields[$key] = "'" . mysql_real_escape_string($value) . "'";
    }
}

mysql_query('INSERT INTO tablename (' . implode(',', array_keys($fields)) . ') VALUES (' . implode(',', $fields) . ')');
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Quotes are not magic, the PHP interpreter sees this:

"checked=" -- STRING
checked -- NOT STRING
":" -- STRING

There's no concatenation and checked doesn't represent anything meaningful so it's an error. The embedded quotes need to be escaped, or you can use single quoted strings instead:

"checked=\"checked\":"
'checked="checked":'

The $checked = "checked="checked":" part also assigns to $checked when it looks more like you want to test for equality.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Several of the companies I've worked for had a separate designer

My experience differs in that I've only worked for smaller companies/departments where everyone wears multiple hats. Thanks for the alternative perspective. :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster
<option<?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?><?php echo $option; ?></option>

This might be clearer:

<option <?php echo (get_settings($value['id']) == $option or $option == $value['std']) ? 'selected="selected"' : '' ?> >
    <?php echo $option; ?>
</option>
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It all depends on how the file is formatted and how deeply you want to scan. If the int is a word of its own and not part of a larger word, you can just read words and check for the int:

#include <stdbool.h>
#include <stdio.h>

bool is_int(char const* s, int* value)
{
    // Fill in this function. strtol() is a good start for testing for int.
}

int main(void)
{
    FILE* fp = fopen("file", "r");

    if (fp)
    {
        char word[BUFSIZ];
        int needle = /* The int being searched */;

        while (fscanf(fp, "%s", word) == 1)
        {
            int value;

            if (is_int(word, &value) && value == needle)
            {
                puts("FOUND");
                break;
            }
        }

        fclose(fp);
    }

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

In { echo ' selected="selected" } , the PHP string isn't closed.

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

Web design these days is more about dynamic pages than static, so you probably won't just be using HTML and CSS. Using things like Javascript, PHP, ASP, and databases is a lot easier when you have some programming experience. If you can't work with those technologies, you could probably still get a job skinning/styling pages, but you won't be as marketable as a web designer.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I wouldn't use recursion for this, but that doesn't mean your way is wrong if it does the job.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If it's not a library that was built for Windows, you won't be able to use it.