deceptikon 1,790 Code Sniper Team Colleague Featured Poster

my interst is C only.

If you only care about C right now then I'd suggest reading the standard and attempting to implement parts of the standard library. On top of learning how to properly use the library by writing it, you'll also learn a lot about computer science in the process.

nitin1 commented: hesitated my mind.. thinking to start with ;) +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

it is request to you that if i again by mistake post any thread at wrong place(as i will try my best not to do it now), then simply re-place it rather than again giving 2 points. at the end, it's your wish.

Everybody follows the same rules and everybody suffers the same consequences for breaking them. There are no exceptions, even the moderators and admins are required to follow the rules happygeek has repeatedly linked you to.

So no, we won't make an exception for you. The rules are basic common sense, easy to understand, and easy to avoid breaking.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but why don't you buy a system rather than building it own your own ?

Because pre-built systems are never perfectly tailored to my needs, and often use cheap parts.

secondly, what exactly do you mean from scratch ? ;-)

From nothing.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A good trick for avoiding this type of mistake is taking the size of the destination pointer rather than hardcoding the type:

int **m = malloc(5 * sizeof *m);
...
m[i] = malloc(5 * sizeof *m[i]);

This works because sizeof doesn't actually perform the dereference, it just evaluates to the size of the result as if had it been performed.

nitin1 commented: awesome trick i must say ;) +2
np complete commented: cool :) +3
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

no, by that i mean there are 2 slots in my PC . but they support 2 GB RAM only.

Each, or combined? If it's each then your maximum is 4GB, otherwise you can still upgrade to 2GB without any problem.

So you build PCs also ?

I built my work machine from scratch and my home machine has been frankensteined to the point where you can call it a scratch build.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yeah, that won't work at all. Move the return statement ouside of your loop:

list::Node * list::Index2Pointer(int index)
{ 
    Node *ptr = first;                          
    for (int i = 1; i < index; i++)
    {
        ptr = ptr->next;
    }
    return ptr;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@deceptikon i didn't get what yu trying to say. will you please re-write it in some other form ?

No offense, but I couldn't care less if you understand my post because it wasn't intended for you, it was intended for Garrett85.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So isn't RAM is responsible for increasing the number of processes at a time rather than increaing the speed as your said ?

The more ram you have, the faster your machine is because less time is spent swapping pages between the hard drive and available memory.

secondly, my PC supports only 2 PC RAM at a time. So what to do now ?

If by 2 PC RAM you mean your system board has two slots, you're golden unless the only chips you can find are 512MB or less.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

are x and hx also want single byte object ?

What? You just asked if %hx was a short and I said yes. How could %hx be both a short and a byte? %x expects a regular length integer (int or unsigned int).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

SO according to you, what should be the RAM for any PC if he is using window 7 and want best performace.

I won't build a Windows 7 machine with less than 4GB.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

x is hexadecimal. hx is short hexadecimal?

Yes.

So how comes the point of char and unsigned in between this ?

%hhx expects a single byte object and converts the value as hexadecimal.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

is there any problem if i am using window 7 with 1 GB ram ?

That's the minimum requirement for Windows to function with "acceptable" performance. If you want to open any other programs and have them function with any kind of acceptable performance, you need more ram.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

what exactly hhx is doing ? i have listend and used hx only and x. but what is hhx in the above code ?

hh is a new length specifier beginning with C99. It means that the object is the size of a signed or unsigned char being used as a small integer rather than a character.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You've been using Windows 7 with only 1GB of ram? Yes, you'll see a marked improvement by adding another gig.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

when i have used extern int i; now it will refer i which is outside or extern to the file . right ? then in the next line, i am writing int i=10; then again there is another i for the compiler. So now which i will be used ? thanks.

If you have two definitions of i in different files then the code will fail to link. If the definition in the same file as the extern declaration is the only definition then the extern declaration will refer to it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So according to you, it it will not work because it is not defined ?

It won't work if it's not defined. It if is defined then it'll work fine because that's the use case for extern.

secondly, isn't this an error as i am saying to compiler that x is defined else where and again i am defining another x, so isn't it a re defintion of x error ?

I fail to see what's so complicated about this.

  • You may have one definition, period.
  • You may have many declarations.
  • Code will not compile without declarations.
  • Code will not link without definitions.

That's all, don't overthink it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The error isn't unclear or ambiguous. width doesn't have a predictable value when you try to use it. You probably wanted another input request to fill it in just like length:

#include <iostream>
#include <cmath>

using namespace std; 

int main() 
{ 
    float length;
    float width;
    float area; 

    cout << "Enter The Length Of The Rectangle: "; 
    cin >> length; 

    cout << "Enter The Width Of The Rectangle: "; 
    cin >> width; 

    area = length * width; 

    cout <<"The area of the rectangle is : "<< area << endl;

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

So is there any reason to use Windows Forms over WPF ?

Backward compatibility comes to mind. WPF was only added in .NET 3.0, and many of us still maintain "legacy" .NET applications (I still have a few targeting 1.1) or specifically target 2.0 for maximum portability.

Lack of desire to learn yet another API also makes sense. Microsoft has ADD when it comes to their GUI libraries. Once we learned Win32 they gave us MFC. Once we learned MFC they gave us .NET. When we got comfortable with Win Forms, they rolled out WPF. Every time the new API was the wave of the future and "you'll be using this from now on". I bet once we're comfortable with WPF they'll change their mind again and roll out something completely different.

Reverend Jim commented: Couldn't agree more. +11
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If the question is unclear to you, please let me know.

The point of this exercise is unclear to me. Is it just random homework from a teacher who thinks trivia will somehow make you a better programmer? Or do you have an actual real world need?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can you post the implementation for Index2Pointer? That should be sufficient to write a test program.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

These days all implementations ought to be compatible with the C standard.

That's where it gets tricky. There are four versions of the C standard at present:

  1. C90: The first official standard from ISO in 1990. All relatively modern compilers claiming to be C compilers should (and will likely) conform to this one.
  2. C95: C95 isn't really a full revision, it's C90 with normative addendum 1 from 1995. All modern compilers should (and will likely) include normative addendum 1 and thus support C95.
  3. C99: The second revision of the standard in 1999. Most compilers will not support this standard, or will only support it piecemeal.
  4. C11: The most recent standard from late 2011. C99 compilers are quickly moving to support C11, if they don't already, but non-C99 compilers aren't likely to in the near future.

If you're writing portable code, it's probably best to assume at most C95. Or you can take the perspective of "if it's standard, it's portable", and let consumers of the code find a conforming compiler.

And on a side note, Turbo C doesn't fully support even C90. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

try it by using 0x%02x instead of %00x
You can also use 0x%x.

printf() supports an alternate formatting flag that will prefix 0x or 0X for you:

printf("%#02x ", array[i]);
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Well, in that case, just use textboxes and do ALL the validation you want in your code.

On a somewhat related note, most (perhaps all) of my clients who are keyboard oriented for speed will have needs beyond basic dates as well, which makes textual input for the usual date controls insufficient. For example, I've written a "quick date" validation method several times to handle things like 010101 (ie. 2001-01-01). A text box is pretty much the only option there because date controls puke on the compact form.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Would it be in appropriate for me to ask if you could send the problematic image to me through email? That's easier than playing 20 questions until I can find one of my own that matches what you have and reproduces the issue. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You'll need to catch and handle the SIGINT signal:

#include <stdio.h>
#include <signal.h>

volatile sig_atomic_t caught = 0;

void handler(int signum)
{
    caught = 1;
}

int main(void)
{
    signal(SIGINT, handler);

    while (!caught)
        puts("Booger");

    puts("Got it!");
    getchar();

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

But at least it's widely documented and doesn't have a horrible naming convention.

We may disagree a bit on what constitutes a horrible naming convention. ;) I won't try to defend the conventions from POSIX, but Win32 names are either excessively verbose or annoyingly hungarian.

I've never seen Dirent.h or any of those includes before.

They've been around for decades. I take it you've worked primarily with Windows systems and only recently moved to Linux? There's going to be a learning curve because even though the basic concepts are similar, the concrete details are different between operating systems.

triumphost commented: +1 I just moved to linux yes. I <3 Hungarian & CamelCase conventions lol. +6
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

when i use extern int i; and it is also present in other file, then after that i can use it normally ? right ? like x=10 or int x=10 ? i think after declaring i just need to use x=10 only as i have already specified that it is int and extern. am i right ?

When you say extern int x;, you're saying that x is not defined here. Therefore it doesn't act as a definition at all. Whether a subsequent x = 10; succeeds or not depends on the presence or absence of a definition somewhere else (which may be in the same translation unit).

secondly, we say that declaration don't allocate memory, that means when i am writing extern int x then it will refer that variable present in the other file automatically ?

That's a reasonable statement.

thirdly, will it be wrong to write

No, but it would probably make little sense to do so since a definition is also a declaration.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are we talking about manipulating clipboard data or catching command line signals (though I'm not familiar with ctrl+v as a signal)?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why is there so little support for plain C++ on linux though? :S

I find it funny that you complain about lack of C++ "support" by the POSIX libraries, then turn around and compare it to the Win32 API (itself a C interface). What makes you think that FindFirstFile()/FindNextFile() and the WIN32_FIND_DATA structure are any less "C" than opendir()/readdir() and the DIR structure?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How big is the chance of such a corruption?

Not big, but big enough for me to question why you're doing a byte-wise copying loop over a network instead of using standard libraries.

The current logic is working, and gives me quite a bit of control, therefore I would not part with it immediatly.

Smells like "not invented here" syndrome, to be honest.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd say start by getting a simple barcode font, such as IDAutomation's free 3 of 9 font and creating some images. The 3 of 9 symbology is dead simple to encode and decode (it's really just a string with asterisk delimiters), which makes it a good symbology to get your feet wet. The hardware readers are also cheap, and there are free software libraries for reading 1D barcodes.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you want to increase the element that you find you would use the post increment operator not the pre increment operator.

The prefix operator is a better practice when the result of the expression doesn't matter. The reason for this is because conceptually prefix increment and decrement are faster due to no need for a temporary. Prefix increment works conceptually like this (not valid C++):

int& operator++()
{
    value = value + 1;
    return value;
}

While postfix increment works conceptually like this (still not valid C++):

int operator++(int)
{
    int temp = value;
    value = value + 1;
    return temp;
}

If you need the result then the difference matters because it's the difference between evaluating to the unincremented value versus the incremented value. But for statements like ++value; versus value++;, the result is ignored. Therefore it's best to use the version that has potential to be faster: ++value;.

For built in types it's largely a moot point because even the first C compiler optimized away the conceptual temporary. I think even Miracle C (the canonical "bad" compiler) performs this optimization. However, C++ introduces user-defined types, where the temporary may not be optimized away. You'll notice that people will recommend prefix increment or decrement for iterators rather than postfix, and this is the reason why.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

For updating the ProgressBar

That makes sense, though an equally viable perspective is that each file is a transaction and the progress bar tells you how many transactions out of the total have completed rather than taking granularity into how progress of each transaction. You don't really care about partial files, after all, only complete files. If a file is partially complete then that's an error condition.

My concern here is that manually copying a file introduces risk of corruption that File.Copy() will be more likely to respond to correctly.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

what happents when we say int frequenct[frequencysize] = {} . does it do a thing or if it doesent why should the writer put that bracket open and bracket close

Read the comment for that line. It says "initialize frequency counters to 0". That should give you a hint of what the empty braces do. To be more specific, if you have an initializer where the number of items in the initializer is less than the number of items in the array, the remaining items in the array will be default initialized. So this:

int a[10] = {22, 33, 44};

Will initialize a[0] to 22, a[1] to 33, a[2] to 44, and all other elements to 0 since 0 is the default value for int.

and the second part is ++frequent [ responses[answer]] two things about it first of all what will be ++ and a little talking about it , like which element in array will change ?

Let's simplify first, because using an array item to index another array can be visually overwhelming if you're not used to it (and sometimes even if you are):

{
    int index = responses[answer];

    ++frequent[index];
}

Does that help make what's happening more clear?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Does anyone know tutorials for link list to be able insert,delete,cout list,give id and time

ID and time look to be node values, which are trivial to retrieve once you have a node reference. Since you asked for a tutorial, I'll give you a tutorial. :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

While one says "definition occures once through the program( memory is allocated once ), but the declaration can occur many times.", the other says "This means that the declaration is only one throughout the program but definitions can be many."

The first one is sufficiently accurate and the second one is completely wrong. I suspect the second one was written by someone who doesn't really understand the terminology and is using the wrong terms for the concept they're trying to explain.

Walt's explanation is reasonable, but a somewhat simplified version of how C handles object declarations and definitions. I'd recommend going with two guidelines that remove the special cases and leave you with a very simple result:

  1. All declarations are qualified with the extern keyword and have no initializer.
  2. All definitions include an initializer.

With these guidelines, int x; is no longer an option. It can either be a declaration:

extern int x;

Or a definition:

int x = 10;

Now there's no ambiguity and the two are easy to identify.

x = 10;, of course, is an assignment and completely unrelated to declarations and definitions excepting the assumption that by naming the object there's a declaration in scope and by using the object it's already been defined. ;)

nitin1 commented: quite good! +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This is wrong:

char *string;
printf("Enter a string of integers: ");
scanf("%s", &string);

There are four bugs here, and one of them is fatal. The fatal bug is that you're assuming an uninitialized pointer somehow points to infinite memory. Pointers must point to memory that your process owns, either by using the address of an existing object, or by allocating memory explicitly. You don't need a pointer here anyway, so just make string an array.

char string[100];

The second bug is a type mismatch. Since string is already evaluated as a pointer in the scanf() call, adding the address-of operator changes the type to a pointer to a pointer to char when scanf() only expects a pointer to char. This invokes undefined behavior because you're lying to scanf().

The third bug is also in the scanf() call and it's a failure to specify a field width for string input. Without a field width, the %s specifier is no better than gets() in terms of buffer overflow safety.

The final bug is a bit subtle, and Windows compilers generally don't exhibit symptoms. But if you want your code ot work everywhere, always flush stdout when displaying prompts that don't end in a newline. There are three times when an output stream is flushed (and for stdout that typically means the string shows up on your monitor):

  1. When the buffer is full.
  2. When a newline is printed.
  3. When fflush() is called.

You don't control the buffer being …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Question: Why are you copying bytes manually rather than using File.Copy()?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The code snippet dates back to june 2012 I'm guessing when daniweb was using the old vbulletin.

The switchover was in mid March, but I won't deny that there were growing pains as we shook out bugs. This issue may be a combination of migrating BBCode to Markdown and a bug that was fixed around June.

As with any formatting problems, feel free to report them so that they can be fixed by a moderator. And if you can find a recent instance of this issue (say from August 2012 forward), that would be helpful in identifying a current bug rather than something we've already fixed but haven't cleared out all of the casualties.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What do you mean by mature ? Is that means they are excellent programmers ?

It means they're mentally and emotionally stable, capable of putting aside any ego when wearing the hat of authority, and able to make make objective decisions based on a calm judgment of the situation. Basically the usual definition of mature when used to describe ideal authority figures.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Im sorry i just didnt know how to explain it well

You don't need to explain the mechanics, just the intended behavior. For example, what is the user of this feature trying to accomplish? What information do you need from the user and what result do you produce from that information?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It does -- all pointers have the same size.

Between object pointers an function pointers, all bets are off. But even for different pointers to object types it's not guaranteed that the sizes are the same. Though you've very likely only worked with systems where pointer size matches the address size for all object types (16-bit, 32-bit, 64-bit, etc...) since that's by far the most common.

Further, I can't think of any good reason to assume the size of a pointer or that all pointer sizes are equal. Any code that needs to make such assumptions would probably be very poorly designed, in my opinion.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Assuming the ISP really is the problem (I find that difficult to believe for YouTube), get another ISP.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i dont have YesNo buttons that was just an example

It would be prudent to explain exactly what you want. It's irritating when I give a viable answer to a question and then the response is "that won't work because what I asked for isn't really what I need".

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How about using a message box with the Yes/No buttons option?

switch (MessageBox.Show(prompt, caption, MessageBoxButtons.YesNo)) {
    case DialogResult.Yes:
        // Do something for yes
        break;
    case DialogResult.No:
        // Do something for no
        break;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Do some research on virtual memory and paging. The answer is that active pages will use RAM while inactive pages will be moved to hard disk space until needed. Provided there's sufficient hard disk space to hold the inactive pages, the OS will behave as if there's infinite memory (at the cost of performance in moving pages around).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

so I was wondering if me learning the win32 api is a waste of time and I should use some of the mentioned libraries for developing windows applications ???

No and yes, respectively. While you should prefer higher level GUI libraries for various reasons, it's still a good idea to learn the Win32 API because it gives you that much more flexibility. For example, I use .NET primarily, but when the framework doesn't do what I need or does what I need but too slowly, knowing the Win32 API means I can drop down a level and get the job done.

This happens more often than you'd think for production software because .NET is notorious for being sluggish on the redraw, and perceived performance is very important.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Introduction to Algorithms by Cormen, Leiserson, and Rivest is a good start. They use pseudocode for the implementation details.

semicolon commented: Thank you +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If it's an intermittent problem, it seems pretty rare given a glance at the most recent snippets. I strongly doubt that the code was posted that way even unintentionally, but without solid reproduction of the issue there's not a whole lot I can suggest beyond keeping an eye out for future instances whenever someone posts a snippet.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

say yes, if you want to have a look ;)

Just post the link. It's not like you have any reason to avoid that for a public YouTube vid.