deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But I don't have any books

I can't see any way that could go wrong. :rolleyes: Here, read this.

plus.. we didn't reached advanced functions like that..

Functions returning void are conceptually more basic than functions returning a non-void type. You're placing an unreasonable weight on the word "void" to mean something far more complex than it really does.

Can I have your explanation on what voids are? Maybe I can understand it. ._.

Maybe you can, but since I already explained what void means in the context of a return type and you didn't understand it, I'm not optimistic that repeating myself will change things until you have a stronger understanding of functions in general.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Actually what happens is we get error in realloc function written in gfunc_Realloc Function in line 174

As a proof of concept, replace realloc() with the corresponding free(), malloc(), and memcpy() process. I'm willing to bet the error you get is happening in free(), which means you've corrupted the memory somehow. This corruption typically occurs by writing beyond the bounds of requested memory from a previous allocation. Very often these areas are specially allocated by the memory manager and hold bookkeeping information that will be used by free().

That might point out the problem, but it certainly doesn't locate the root cause. For that you need to do some serious delving into your code to see where the pointer is being used inappropriately.

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

i have to do division without divison/multiplication/mod operator.

Yet another dumb assignment that serves no purpose in reality. Can't educators think of more practical exercises?

nitin1 commented: seriously , if u were my teacher than today i may be somwhere else ;) +2
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can also select which language to compile as in the project properties: Configuration Properties -> C/C++ -> Advanced -> Compile As.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'll suggest that you reread your book's chapter on functions, because you clearly don't understand the concept.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

void as a return type for a function means nothing more than the function doesn't return anything. It ultimately just means that you can't do this:

void function();

...

some_variable = function(); /* Can't do it, function doesn't return anything */
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Discussion of software development specific topics with a primary focus on helping both students and professionals with their specific problems.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The person either didnt want to do it

I'd argue that if he didn't want to write such a simple program he's at a level where Gonbe's code would be easily recognizable as plagiarized by any teacher with more than two brain cells to rub together. That's assuming he's both lazy and unscrupulous enough to turn in the program as if he wrote it.

Our primary concern when it comes to homework solutions is cheating. We don't want to be blacklisted, which has happened before (hint hint, Gonbe, it's not just an arbitrary guideline). Solutions that are conceptually helpful by solving the problem or a similar problem, but practically unhelpful because they're too advanced to be turned in directly are generally acceptable because it makes cheating difficult.

or didn't know how so by you giving them the answer it does them nothing but get them further behind in their lessons.

Let's consider two of the most likely situations where the student is unwilling to take an example and learn from it:

  1. He's in a programming class: In this situation, he would have failed in short order regardless, so getting further behind isn't the catastrophe that your statement makes it out to be.

  2. He's teaching himself: Nobody is hurt in this situation except him, and if he's unwilling to do any work with provided examples and working code to really understand them, failure in the venture was guaranteed before it even started.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What result are you trying to achieve here?

Nomi55 commented: wanted to print a shape like that in row 1 and 3 there are 4 astericks... +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are these all parts of the draw methods?

http://msdn.microsoft.com/en-us/library/e06tc8a5.aspx

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

const int DELAY_IN_MICROSECONDS = 100;
Sleep(DELAY_IN_MICROSECONDS);

Sleep() takes a parameter that represents milliseconds, not microseconds. I just wanted to point that out in case readers don't study the documentation you linked to closely enough, and then find Sleep() doesn't have the granularity they want.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Uhh.. I need help in understanding this code. My friend wants me to understand this. I understand some parts of it..

Which parts don't you understand? Nobody is going to explain the whole program line by line, and we can't read your mind. I fail to see what's so difficult about asking a specific question.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Okay. Good luck with that.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Because when you rename the structure list to list_t but nowhere was struct list defined before that line.

That's not a problem. You can use an incomplete type as the alias in a typedef, provided there's no instantiation of the typedef that would require the alias to be complete until there's a definition for the alias. Since the only use of list_t prior to definition of struct list is through pointers to list_t, all is well.

My guess would be that list.h is included, but list.c either isn't in the build or is being linked in the wrong order. So flange.c sees the definition of list_t, but not the definition of struct list.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So...what output does the program produce and how is that not what you want?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But I don't know how to implement the necessary code to print the number pyramid.

It's a little more complex than what you've done. I'd suggest breaking each line down into four parts:

  1. Leading whitespace.
  2. The leading half of the row.
  3. The midline of the row.
  4. The trailing half of the row.

Leading whitespace is obvious. For the numbers, let's say you have the line "34543". The leading half is 34, then 5 is the midline, then 43 is the mirrored leading half that acts as the trailing half. You'd count up to get the leading half, then count down to get the trailing half.

The rotating numbers would be tricky if you used straight arithmetic like most of the number pyramid exercises, so I'd recommend storing the numbers separately and using a straight width counter to determine how many numbers to print. When you reach 10 counting up, reset the number to 0, and when you reach -1 counting down, reset to 9.

An alternative is to use a string as the "number list" and a rolling index to handle the wrapping. The rolling index would work the same way as above. The rolling behavior can also be performed with the remainder operator and modulo arithmetic, but that might be confusing things too much. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

and if I try to read columns with this code snippet:

I notice that you're reading the value for the rows and columns into a and b, respectively. But you try to print rows and columns. Since you used the address-of operator for a and b, I can make a reasonable guess that they're not pointers referencing rows and columns. That's your immediate problem, but fixing it still won't produce the correct output (see below).

I also notice that you didn't pay close attention to the code example I gave you. %[^:] is the specifier, the scanset is not a modifier for the %s specifier. Your format string has %[^:]s, which means scanf() will look for a literal 's' in the stream, then any amount of whitespace, then a colon. There's no way your format string will work, because it depends on two mutually exclusive values for the next character. The scanset stops on a colon without reading it, but the next expected character is the literal 's'; it can't be both a colon and an 's'.

The following is correct, read it very carefully:

fscanf(infilep, "%[^:] : %d\n", storage,  &a);
printf("temp is %s, %d\n", storage, a);
fscanf(infilep, "%[^:] : %d\n", storage,  &b);
printf("temp is %s, %d\n", storage, b);

Remove the space just before the colon in the fscanf() format specifier string. Not sure it will fix it but worth a try.

It won't have any effect. Literal whitespace in a format string just …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I was wondering is it at all possible to programatically select an area of an image to display?

Of course. Though how you do so depends on what kind of processing you're doing. Sometimes a thumbnail will work, other times you can simply crop, still others might have you zoom in to a specific area (which may or may not be detected programmatically).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

can i know more about device drivers??

Probably, have you consulted google? If not, please do so. If you have, please ask a more specific question.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My son said to ask if you've heard of (or seen) Wolfen Spice.

Yes indeed, assuming he means Spice & Wolf. Both seasons are excellent, but kind of heady if you try to follow the merchant explanations. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's a logical address.

I may not be clear in the defination of physical and logical address. thanks if you can help me ;)

Physical addresses are the actual spots in memory. Logical addresses are a set of pretend addresses assigned to each process that are mapped into physical addresses by the OS when the process is loaded. The benefit of logical addresses is that an executable can refer to specific addresses for things such as entry points and jumps without worrying about those addresses being unavailable at runtime. They're always available because they're not real.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

like nlogn +n , then the overall complexity is ?

nlogn, because for the most part, insignificant factors are ignored. nlogn overwhelms n, so n is tossed away.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Some early thoughts...

Tonari no Kaibutsu-kun: Exactly as expected, so far so good.

Suki-tte Ii na yo: The art seems off for the female protagonist, especially the early range of facial expressions that belie her initial personality. I'm also not a fan of the selected voice actor's portrayal at this point. It may grow on me, but I saw her more as the more deadpan and cold portrayal shown by the female protagonist of Tonari no Kaibutsu-kun. It's kind of a shame because out of the two this one is the one I was most keen to see, but it's still early.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Hardware typically comes with device drivers that provide an interface for system and user level applications to use the hardware.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Give it a try first. We require that you provide proof of effort on homework problems.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

the printf() might not be inside if(), but if() states the condition when partition() will be called (recusrsively).. so doesnt that make the printf() dependent on if() ?

It does, but you're thinking of things in the wrong order. When low and high are equal, the printf() still executes even though the contents of the if statement do not.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm having trouble seeing the individual strings in the watch window when I'm debugging my code. Is there any reason for that?

The debugger probably isn't expanding dynamic strings, which is what std::string uses internally. So what you're seeing are the concrete data members. The actual data of the string is probably represented as an address (like 0x12345678), and you might be able to expand that as well to see the string contents. It really depends on the debugger in question.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That's somewhat high level and vague on functionality details, but it's certainly a good start.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The problem is a conceptual misunderstanding about pointers, but ultimately it boils down to this:

structure[x][y] = readData;

All of the pointers in structure are pointing to the same array, and that array is constantly changing because you use it as the temporary buffer for input. What you really want are copies of readData, not references to readData. The easiest way to do that would be make structure an array of std::string, not pointers to char:

std::string structure[100][100];

readData should also be a std::string so that you don't have to worry about buffer overflow. It would immediately solve the current bug in your code where getline()'s limit exceeds the size of the array (ie. it should be 9, or sizeof(readData)).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

By the way, it was something wrong when I posted this, so had to put all the text in a code block.

Our code validation algorithm will very likely prevent you from posting when you format your text like a letter or formal prose (ie. leading paragraph indentation) because leading whitespace is how our formatting language recognizes and highlights actual code.

You can (and should!) avoid this by starting all non-code text lines at column zero.

p.s. I fixed your first post. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i dont understand why i get output for cases (step number: 3,4,5 and 8,9,10) when "low" and "high" are equal, where as the if() condition in the partition() block states recursion only when low<high...

That might be confusing if your output were performed inside the if statement's body, but it's not. So regardless of the values of low and high, you're still printing output; the two are unrelated.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If the only requirements are to use switch, for, and if constructs then your imagination is the limit. Start by writing down use cases for a car rental service, this will help you get a feel for features the application will need to support.

You can't write a program that you don't understand, so understanding the problem to solve is priority #1.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your format string is incorrect. The %s will read until the first whitespace, so a literal ':' won't be matched (since it was already extracted) and will cause the fscanf() call to fail. If you want to match it then this would be better (example using the first line):

char temp[80];
int rows;

...

fscanf(infilep, "%79[^:]: %d\n", temp, rows);

Note that temp is an array rather than just a char. It doesn't seem like AD made it clear that your use of a char is very broken. Also note that I included a field width matching the size of the array. This ensures that you don't experience undefined behavior from buffer overflow if the string in the file exceeds the size of the array.

The actual specifier is a scanset. It looks for any character that isn't a colon (including whitespace!), as the '[^' scanset is like a logical NOT. This leaves the colon to be matched by the literal in the format string.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

All members have a one time option to change their name from their profile page. The link is at the bottom and is cleverly disguised as a button labeled "Edit Username".

Mike Askew commented: Damn this sly button, I shall start a hunt for it. +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Wait, you're a novice and you've been given an assignment to write a floating point pow() without any math.h functions in the first few weeks of a CS course? Something seems off there, because this isn't exactly a trivial exercise.

For example, take a look at the implementations here. They're designed to be short and simple, yet pow() still depends on a relatively large amount of scaffolding.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

"Floating Point Formats Not Linked Abnormal Program Termination"

That's a fairly common Borland error. There's nothing wrong with the code, your compiler is just stupid in it's assumptions about the environment for unnecessary efficiency purposes.

Ideally you should go into your linker options and include floating point support so that the compiler doesn't have to make assumptions.

Click here for further information.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why did you create a new thread for the same question?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I am not changing the value of Range inside the loop. I am merely printing out what Range is.

You're not changing the value of Range in the loop, but you should be. Range doesn't change, that's why you keep getting the same number.

There may be some confusion here about what Range represents. It's one number in the range, not all of them.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So, i need create a program that will interpret the source code (obviously the input/output, logical. like 1+1, then it would just output the '2') using the symbol table.

So...you want to write a compiler. If the symbol table is already generated, that simplifies your job, but not a great deal. Tokenizing is one of the easier steps in compilation. The next step, parsing, is where the real fugliness comes in when it comes to the C language, because you can't just use a simple recursive descent parser due to C's complex grammar.

This isn't a problem for a forum post, so I'll direct you to a list of resources.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

However, this code returns the same number everytime.

Please read my previous post again. All the way to the end this time.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but another error came up

If you're going to paste over 100 lines of poorly formatted code with every post then I'll have to ask that you fix the formatting. If you're going to say vague things like "it doesn't work" or "I'm getting an error", I'll direct you here.

kthxbye.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please point out where you're calling birth[i].input().

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Lower_Bound_Rand = rand() % Lower_Bound;
Upper_Bound_Rand = rand () % Upper_Bound;
Range = rand()% Lower_Bound && rand()% Upper_Bound;

So you're saying that Range will be either 0 or 1, with a very very strong bias toward 1. The result of the && operator is a boolean value, and unless otherwise specified each half of the test will compare the result of the expression to see if it's either 0 or not. So this would be equivalent (using your redundant *_Rand variables:

Range = (Lower_Bound_Rand != 0 && Upper_Bound_Rand != 0);

You already know how to find a random number between 0 and an upper bound, so why not use the difference of the upper and lower bounds as the upper bound and then add the lower bound?

Range = rand() % (UpperBound - Lower_Bound + 1) + Lower_Bound;

This will shift the range such that it starts at the lower bound and doesn't exceed the upper bound. Not the +1 in there to make the upper bound inclusive. Otherwise it won't be due to how modulo arithmetic works.

You also don't change the value of Range inside the loop, so it'll never be different. The expectation is that you recalculate a new random number for each iteration of the loop.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Visual C++ supports kbhit() and getch() in the conio.h library, together they do what you want.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I mean i know that i am accessing data outside the array but where?

You use a debugger to figure it out. Most debuggers will give you the option of setting a break condition; you can use a condition of the array index being out of range. Alternatively, you can go old school and just add debug output at strategic locations and take note of the program's current state when it bombs.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This paper came up as hit #1 on google. Have you done any reseach on the subject?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but doesn't void* make it a pointer ?

Show me where there's a cast to void* here:

printf("%d\n", *inputVal);

And here:

enqueue(queue, *inputVal);
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

inputVal is not a pointer, yet you try to dereference it like a pointer.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But maybe you work in a less innovative software company with a stable product portfolio?

Or maybe you've worked in a company where the R&D department is poorly managed. ;) I work as a consultant, and as a result see how many different companies of different sizes work. And while I've seen some scary shit in terms of management and processes, even the companies that are on the cutting edge of innovation or have to deal with constant change haven't struck me as being chaotic.

I'm not sure what to say at this point because it doesn't seem you can be convinced that the development environment of every company isn't a clusterfuck. I can only conclude that you've already made your decision to not become a developer, so there's really no point in continuing this discussion.