deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i suck because i had zero knowledge on Unix or Linux

No, that's silly. Will learning other operating systems help round you out as a developer? Sure. Does your "goodness" as a programmer depend on knowing *NIX platforms? Absolutely not.

Let me put it this way. I'm primarily a Windows developer, but I do know several Unix variants. In my work, that knowledge has benefitted me in only four areas:

  • Converting Linux-specific code to Windows (rare).
  • IT support/consulting where a Unix system is in place.
  • Navigating a Linux web server.
  • Recognizing file formatting differences between Windows and Unix (eg. newline representation).

In other words, the benefit has been largely minimal and I could easily have managed without any intimate knowledge of *NIX.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Understanding how buffer overflows attacks are implemented is key to understanding how to prevent them.

Hardly. Preventing buffer overflow in code is not dependent on understanding the details of how to exploit such a security hole. There's a difference between "this is buffer overflow, and here is how you avoid it", and "tell me how this buffer overflow exploit works". The former teaches safe coding practices while the latter essentially teaches one how to write exploits.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The part I’m struggling with is getting the date out of the string which will work for different string lengths

So here's my thought process as a professional (as if that adds weight to my comments...):

  1. Is the date always in the same place (ie. at the end of the file name before the path?)
  2. Is the file name always formatted the same way?
  3. Is the date formatted the same way in all cases?
  4. Does the date format always have the same number of characters?

The answer to those questions changes the solution. It could be as simple as this:

private DateTime ExtractDate(string path)
{
    var file = Path.GetFileNameWithoutExtension(path);
    var fileDate = file.Substring(file.Length - 10);

    return DateTime.Parse(fileDate);
}

But this code smells funny, and I'd definitely ask about it in a code review, because it seems brittle in the presence of variations of the date format.

A better approach might be using a robust regular expression to find a date at the end of the string, then parse that. But if there's a format guarantee then this approach would be unnecessarily complex.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Done. Show me yours and I'll show you mine.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Do you mean what rules you must follow for a valid identifier, or guidelines for informative variable names?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It rather depends on the type of the array. If it's anything but some variant of char, I'd recommend using a loop to avoid nasties by diddling with individual bytes of a multi-byte type.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Undefined behavior is unpredictable by definition. You could certainly figure out why it "works", but it would be specific to that version of that compiler.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

At a glance, the logic looks okay. There are some nasty habits that should be eliminated though:

#include<conio.h>

The conio library is not needed in this program, it and all functions from it should be removed to maximize portability. This header is not standard, so you're basically limiting yourself to Turbo C variants.

void main()

This is not standard either. If the compiler supports it, you're fine. If the compiler doesn't support it, you've invoked undefined behavior. Given the risk, it's much better to simply use int main() and return 0 at the end.

gets(str);

Please forget that gets exists. In the latest standard it's been deprecated, and there's no way to make it safe. If you try to input a string with more than 99 characters, you're basically screwed. fgets is the recommended alternative.

I won't go into a rant about clrscr and getch, because they're both functions from the conio library and I've already recommended that they be removed. However, if you want, I can go into more detail about why they're bad in this case.

One problem with the logic is that it doesn't take punctuation into account. Let's say your sentence is "Hi fellow pickles, I'm a pickle too!!!!!!". You'd incorrectly say that "too!!!!!!" is the longest word, because bangs aren't excluded from the count.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

...

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Normally I'd point out what's wrong, but in this case it's very instructive to work through what the code should be doing versus what it's actually doing on paper.

Here's a working example you can use to compare with though. It's written in C, but a conversion to C++ is trivial:

http://www.eternallyconfuzzled.com/tuts/algorithms/jsw_tut_sorting.aspx#radix

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Sorry, but discussion of hacking is against Daniweb's rules. We can help you at a high level, but anything more detailed that could be used to create an exploit is prohibited.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Ok, so I tried to change my class properties as Pritaeas suggested, but this didn't work.

It should work, but it's hard to tell why not without seeing a complete bare bones example that exhibits the problem.

Would this be an appriopriate use of (get;set;)?

Yes. In fact, that would be my default choice for publicly accessible data items:

public class TCard
{
    public int Suit { get; set; }
    public int Rank { get; set; }
}

Though in this case I'd prefer to also write classes or enumerations representing suit and rank, since just using int means you'd end up having to validate and error check invalid values.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That's a pretty simple one. There's no definition of the _Clrscr function anywhere in the translation unit. Visual Studio doesn't come packaged with any form of clrscr as a "standard" library, so you need to consider the following:

  1. Did you declare it somewhere but not define it?
  2. Are you using a third party library that declares it but not link with that library?
  3. Was the code written for a different compiler in a non-standard manner?
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

if u want then i can give u the code how to break the sentence into each single word.

Yes indeed. Showing what you already have is a good start.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please read our rules concerning homework.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster
  1. I'm of the opinion that it's always worth learning different languages. However, more important than learning a language in the same family (eg. C# is in the same family as C and C++), learning completely different languages rounds you out as a programmer because you often have to think differently. A prime example is a strictly functional language stretching your brain more than yet another imperative language.

  2. It really depends on what you're doing. You can know as little as grade school arithmetic, or need to be intimate with higher math. Generally, programmers can get away with a reasonable foundation in algebra. I'd wager game programming would be on the more mathy side.

  3. Learning for the sake of learning, not so much, in my opinion. As long as you have a purpose for learning a language, it's all good.

  4. School won't teach you what you need to make it in the real world. I've worked with a lot of college grads who were blindsided by what real software development is like. These days, my opinion is that college isn't worth the money.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes, someone can help. What do you have so far? If you don't have anything, what's your thought process for working it out? Have you analyzed the structure of a sentence to break it down into words?

Note that "help" does not constitute doing work for you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Given a certain measure of development experience, simply seeing the behavior of a program can offer insight into the underlying logic as well.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please read our rules concerning homework assignments.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I am not able to flush stdin here,is there a way to flush stdin?

The only portable way in C (ie. using the stdio library) is to read characters until a newline or end-of-file is found. Of course, this ends up causing a blocking read if the stream is already empty, which you'll find was one of the hurdles for a complete solution in Narue's original post. C++ offers a posibility to work around it, but C does not.

If not then how to make getchar() to take a character as input from user, instead of a "\n" left by scanf in the input buffer??

The '\n' left by scanf is a character as input from the user. Recognizing that when you type the Enter key a newline is placed in the stream is an important concept when working with stream I/O.

fflush(stdin);

Not such a hot idea. fflush is only defined for output streams. On one compiler fflush(stdin) may work fine and flush the stream. On another, it may not do jack diddly. On another, it might crash your computer, delete critical system files, or cause demons to fly out your nose. In other words, fflush(stdin) invokes undefined behavior.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The linked image is nonsensical. Please elaborate on your assignment.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A segmentation fault typically means you tried to access memory outside of your address space. The most common causes of this are a bogus index or invalid pointer.

Also note that the point at which an error manifests doesn't mean that exact line is the root cause. Sometimes the line pointed out by a debugger is wholly unrelated to the problem.

Since it appears this error can be reproduced in a debugger, step through your code and work back from the point it happens. Check your data, check your indexes, make sure that everything looks kosher memory-wise until you find a problem.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What's the rule that determins if it's an inline function or not?

If a member function is defined inside the class definition, it's marked as inline implicitly. If a member function is defined outside the class definition, an explicit inline keyword marks it as inline.

Whether the compiler chooses to actually inline the function depends on the compiler's internal rule set. The short answer is, you simply don't know for sure that a function will be inlined when given the hint. The only way to ensure inlining is to use another method, such as the old #define preprocessor directive.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

More control, you know you have exactly 1 line the are no extra characters interfering with your parsing of the data

With the caveat that your second advantage interferes with the first.

You limit the amount of data read to your buffer size so there is no chance of an out of bounds array access

If the line is longer than the buffer size, multiple calls to fgets are required to get all of it. Ignoring stream errors, fgets will read up to the buffer size (the second argument) or a newline is extracted, or end-of-file. Robust code would account for all of those possibilities:

char *line = NULL;
char buf[BUFSIZ];

while (fgets(buf, sizeof buf, in) != NULL)
{
    size_t end = append_str(&line, buf);

    // Did we read a full line?
    if (line[end] == '\n' || feof(in))
    {
        break;
    }
}

if (line == NULL)
{
    // Handle no input
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

because windows operating system get corrupt instantly

There seems to be more here than meets the eye. If Windows gets corrupt "instantly", that's suggestive of a deeper problem unrelated to the OS itself.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm a little confused about inlining member functions.

It would help to understand how regular functions typically work. A single definition of the code is created, then calling code jumps into the definition to execute the function. Inlined functions have their bodies essentially pasted directly where the call is so that there's no jump and relatively little bookkeeping overhead. For smaller functions that aren't called in a great many places, this can improve performance.

But beware, because inlined functions can also degrade performance by increasing the code size to the point that it crosses cache lines. Or if the function isn't completely CPU bound, any benefit of inlining can easily disappear.

Does all code actually have to be on one line

No, though the shorter the function is, the higher the chance of it actually being inlined. Note that marking a function as inline (or putting it in the class declaration) is just a hint, the compiler is free to ignore it.

or does it simply mean writing the whole function inside the class rather than from outside using the :: syntax?

You can define the function outside of a class and use the inline keyword to the same effect.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

because you said it's "free"

Very true, I should have qualified "free".

and keep referring to having developed software for your "clients" / "customers" with it

As clearly stated in the OP, this class was written for my personal library. The only mention of customers was a tongue in cheek comment by myself and your mention in the quoted text, so it's a little unfair to claim that I "keep referring" to it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Helpful answer to problem.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Wouldn't have been easier to use iTextSharp instead?

Last I checked, iTextSharp didn't support PDF rasterization directly.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

As a side note, Ghostscript is the back-end for ImageMagick's PDF conversion. I'm a huge fan of ImageMagick and its variants.

Not sure what the other products use under the hood, but since most of my work involves custom code, a fairly open API of some sort is critical. Customers tend not to react well to "well, use PDF Converter". ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are any particular one which should be used at specific times?

I favor the guideline that you should use '\n' unless you know that the stream must be flushed immediately and nothing else consistently does it for you. Times where you have a lone output statement and the stream must be flushed with std::endl or std::flush are surprisingly rare, mostly due to tied streams:

cout << "Prompt: "; // No consistent flushing here
cin >> choice; // This statement flushes cout for you

I understand endl flushes the stream (although i'm not 100% what this means)

When an output stream is flushed, the internal buffer is sent to the destination device. For performance reasons, when you write characters to a stream they're collected into a buffer. Then when the buffer fills up, it's written in toto to the target device. The performance benefit is that a potentially expensive operation is minimized by reducing the number of times it happens.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm not sure I understand the need for this restriction. Could you elaborate?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is this WPF or WinForms?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My primary concern would be what kind of pictures are you trying to display? A picture box control may not support them, in which case you need to find an alternative.

As far as picking a random picture, that borders on trivial:

var files = Directory.GetFiles(path, searchPattern);
var imagePath = files[new Random().Next(0, files.Length)];
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Depending on your needs, it could be as simple as:

if (Directory.Exists(path) || File.Exists(path))
{
    // Yuppers
}

But it's somewhat hard to answer your question because it's a little vague. What exactly constitutes "valid", for example? What kind of paths are you supporting? Is this a file path or a folder path, or could it be either?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Without looking at the specs, or knowing your needs, I've had good experiences with both brands (my current mobo is ASUS). To properly answer your question, I'd need more details.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The second method is obviously easier to read.

Provided blocks are indented correctly and at a reasonable depth, the location of braces doesn't really matter...to a certain extent. I think you'll find that your preference varies over time. Right now you clearly prefer Allman bracing over K&R, but that might change.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It depend on the compiler designers I guess.

Language designers, rather. Allowing no return statement at the end of a function returning void is a hard rule in C++ that all compilers must adhere to.

Some programmers like to be explicit though, and always include a return statement regardless of what's allowed. One example is main. Despite returning int, a special rule states that you can omit a return statement and it will have the same effect as return 0;. Not everybody likes that rule because it's very niche and feels like an exception (only applies to main) that can cause confusion, so they always use a return statement.

I say, whatever floats your boat. Both are perfectly valid and acceptable. It boils down to personal preference. :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

why they put it ??

They're being explicit, I suppose. If a function returns void, there's no need to place a return at the end. Falling off the closing brace does it automagically.

what is the logical meaning of it ??

It means that the function will hand execution back to the calling function, but return no value.

is it the same as (return0;) ??

No. return 0; does return a value, and cannot be used in a function with a return type of void.

shahera.arafat commented: void print(node*head,int id){ node*p; p=head; while(p!=NULL){ if(p->id==id){ cout<<p->id; return; } p=p->next; } cout<<"node doesn't exist"; } this (return;)here,for what did they put it ?:/ +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Another way round, is it possible for super-experienced C# programmer to create (when given enough time) advanced browser (like Mozilla), advnaced text/document editing program (like Word) and advanced verbal and textual communication software (like Skype)?

Yes, absolutely.

The question is, is C# same. Is it only limited to what I've seen, "1 dialog screen, few buttons and work."

Current versions of Visual Studio are supposedly written in C#. Does that count as all-mighty-creation? It's far from a toy application with one dialog, a few buttons, and some work. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

it consists out of multiple files including .vshost., I don't see such files in Word, Skype of Firefox

The vshost files are specific to your installation of Visual Studio for debug and settings information, they're not included in a deployment package.

One gives a lot of knowledge of C# and Visual Studio 2013, would be able to reconstruct every "civil" program?

One could create a decent facsimile, sure. You mention Skype, Word, and Firefox. None of these are written strictly in .NET.

Or is it limited only to certain actions like Batch or JavaScript?

I'm not sure what you mean by this, and therefore cannot answer.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Put simply, ASP.NET does web pages and WCF does client/server communication.

J.C. SolvoTerra commented: Thank you. +3
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Were I writing something like that, I'd link the web access and application access with a web service.

  • Web Service: WCF
  • Web Access: ASP.NET
  • Application: WinForms or WPF
  • Mobile: Whatever WSDL consumption API is available for the supported language.
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Consider this: Swap the data with the next node, then delete the next node. This is what I mean by thinking outside the box.

Thinking through these types of problems on a simple data structure like a linked list is invaluable for when you move on to more complex data structures. In particular, this swap and delete technique is very handy with trees. But the reason I'm directing you rather than simply gaving away answers is because if you only know the specific technique for that data structure, variations of it for other data structures don't stand out as readily.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Welp, since ddanbe covered the second error, I'll mention the first. You have a name conflict. The class and method are both called Main. Since the method has to be called Main, change the class to something like Program and the compiler should properly report that your floating-point literal needs a type qualifier.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Did you figure it out? As mentioned before, I really am trying to help, but without flat out giving you the answer.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Make the next node at first??

I'm having trouble deciphering what you mean, but it sounds like you're thinking in the right direction.

Here's a hint: the problem doesn't state that you only have to do this by diddling with the links between nodes.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But you won't learn anything by being given the answer. The trick is to think outside the box a little bit. Naively deleting a node from a single linked list is O(n) because you have to find the previous node for unlinking. So what can you do to avoid needing the previous node?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Done. Show me your solution and I'll show you mine.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A good start in determining what's wrong is asking what it's doing versus what you expect it to do. So...what's it doing that's different from what you expected? :)

I see two problems in particular, one of which will be immediately obvious from the compiler's errors and the second will appear after fixing the first.

I'm not being obtuse, by the way. I'm trying to push you to learn how to figure out your own problems, which is a huge skill to have in programming.