nezachem 616 Practically a Posting Shark

I don't know how to use #define with this program.

Question is, why do you want to use #define in your program?

nezachem 616 Practically a Posting Shark

class

It's a C forum.

nezachem 616 Practically a Posting Shark

First thing which comes to mind is Silk. However it costs fortune, so look for free frontend QA tools. I am not an expert in QA, and can't recommend any.
If your games are browser-based, and you use extensible browser like Firefox or Chrome, study their extension mechanisms.

nezachem 616 Practically a Posting Shark

It's on our list of "if you don't implement this, you fail as a compiler writer" bullet points.

I have to disagree here. A performance of pre- vs post- very much depends on the target architecture. For example, cpu32 has (Ax)++ and --(Ax) addressing modes (intended for stack operations), which maps directly to C *ptr++ and *--ptr idioms. By contrast, it has no hardware support for their peers. A compiler writer may of course artificially slow the predec down to match the performance of postdec, but I doubt anybody would do that.

nezachem 616 Practically a Posting Shark

You probably compiled it as C++, where new is a reserved word.

nezachem 616 Practically a Posting Shark

If you printed it as hex ("%x"), you'd see 10102, which contains ALL the numbers defined as VERSION_***.

<< is a shift operator. A major is 1 shifted left by 16 bits, a minor is 1 shifted left by 8 bits, a patch not shifted at all. Now they can bi combined safely into the single value, because they occupy different bit positions there.

Excizted commented: Useful, thanks :) +1
nezachem 616 Practically a Posting Shark

From what I see in your log, all sockets were created fine, yet non of them successfully connected (you print the client: connect message on connect failure). Now the question is why only one thread reaches line 58. Hard to tell, I would look closely for the deadlock in write_to_log_file.

PS: It is always helpful to include strerror(errno) into the error message.

nezachem 616 Practically a Posting Shark

You don't seem to call print. Your code only calls printf (see line 16 of a nasm code), passing argument as it to print. Of course printf gets confused and segfaults.

PS: You have a debugger. Why didn't you use it?

b main
run
si
si
si
si
si

and find yourself in printf.

nezachem 616 Practically a Posting Shark

But isn't it true that, since the post-increment operator has a higher priority than = , i++ will be evaluated first, but the unincremented value of i will be passed to i

This is true

and i should remain unchanged after all that

while this is not.

An assignment operator has a side effect of modifying memory. A postincrement operator has a side effect of modifying memory. In a i=i++ case, both of them try to modify the same memory.

The standard says that the side effect must be completed at a so called sequence point. If a program has more than one side effect between sequence points, the order of their completion is undefined. I don't think it is a right place to discuss the rationale behind this decision. We just have to live with it.

An expression i = i++ does not have sequence points, therefore which modification happens the last is undefined.

PS: the sequence points are a semicolon; a function call; a comma operator, logical operators etc.
PPS: For example, && is a sequence point, hence i++ && i++ is well defined, whereas i++ & i++ is not. Isn't that funny?

nezachem 616 Practically a Posting Shark

I was wondering should I learn assembly

Yes.

But please do realize that in your whole programming career you almost certainly will never ever write a single line of the assembly code.

So, why bother? A simple answer is to understand how the machinery underneath your C++ really works.

Study some contrasting technologies, line x86, cpu32, risc, vliw, cuda (what other abbreviations can I recall?). Study some 8-bit architectures. Study them all in parallel. Try to port something from x86 to, say, spark. Appreciate how a high level languages simplify your life.

nezachem 616 Practically a Posting Shark

First, I do not understand the sacral meaning of a number 6, especially at line 33. Maybe you know something about how the file is arranged, but in any case I would not rely on magic numbers.

In your situation I'd get rid of line 33, and moved line 32 to 26.

nezachem 616 Practically a Posting Shark

I don't know what to say. I copied and pasted your code. Added amicable.h with the your struct definition. Compiled it with gcc -Wall. Got one warning.

Dump your turbo c, what else can I tell. It's a crap anyway.

PS: ran it, and get an obvious segfault at amic->size = 0 . Please acquire a habit of not using uninitialised variables.

nezachem 616 Practically a Posting Shark

Maybe I am missing something.

here i cannot use my bsearch function.

Why?

all the keywords and operators are arranged in the array in increasing ascii value of characters for single charcater operators.

but how to handle the assignment and relational operators.

Can you just change the comparison function?

please suggest me a way to solve this problem.

or suggest me is there any other method to solve the problem.

Usually for problems like this lex is the solution.

nezachem 616 Practically a Posting Shark

i just want to ask some tips to understand easily turbo c.,.

Tip #1: don't use it.

jonsca commented: Yes!! +1
Salem commented: Solid advice! +18
nezachem 616 Practically a Posting Shark

I wouldn't go that far to declare this code wrong. However, such simplistic approach is inherently dangerous. See for example this article. For more details, also look at this.

Ancient Dragon commented: good points in those links. :) +25
nezachem 616 Practically a Posting Shark

It would be most helpful to have a minimal piece of code which builds and demonstrates the unwanted behavior. Otherwise we can only guess.
Usually you need to flush the stream between writes and reads.

nezachem 616 Practically a Posting Shark

A None value is not displayed by the python shell, as in this example

>>> value = None
>>> value
>>>

However this will work in the Python shell ...

>>> value = None
>>> print(value)
None
>>>

Looks like the old shell has tripped up a few folks lately.

>>> value and >>> print(value) are sort of different.

nezachem 616 Practically a Posting Shark

Did you use a debugger?

Meanwhile, there are few problems here. First, the amicablePair array is allocated, but not initialized. Its elements, which are supposed to be of type int * are garbage pointers. As soon as you try to access them (at lines 55 and 56) you have your memory access violation.
Second, you allocate the array of ints, but pretend to allocate an array of int pointers. It is not exactly what bits you now, but it would bit you later.
To fix your code, change line 37 to

amic->amicablePair=malloc(32*sizeof(int *));

and add initialization:

for(i = 0; i < 32; i++)
    amic->amicablePair[i] = malloc(sizeof(int) * 2);

Don't forget to check for malloc failures, and cleanup properly when you done.

nezachem 616 Practically a Posting Shark

I mean you do in.open() , but don't do out.open() .

nezachem 616 Practically a Posting Shark

Look closely at line 69. What value has out at that moment?

nezachem 616 Practically a Posting Shark

assignment is a sideeffect?

Yes.

if((ifd=open(filename,O_RDONLY))<3)

means:
1. assign the value returned by open to ifd
2. compare it to 3
whereas

if(ifd=open(filename,O_RDONLY)<3)

means:
1. compare the value returned by open to 3
2. assign the boolean result of the comparison to ifd

nezachem 616 Practically a Posting Shark

It is always a good idea to run your code in the debugger.
Meanwhile, a line 3 allocates just as much memory as needed to hold the initializing string. An attempt to catenate something to it results in some stack portion corruption, overwriting most likely the state_in (even if you initialize it correctly, lines 4 and 5 will make it a garbage pointer). Then the segfault at line 7 is imminent.

nezachem 616 Practically a Posting Shark

We do read the original post. And as we do not know the before string, or whether or not there is always a "+" associated with it, we have to make assumptions.

Please forgive my English. OP implied Original Poster, who, in the next message says:

I want to replace only whole words.

Not much room for assumption in my opinion.

nezachem 616 Practically a Posting Shark

Does nobody read my posts? \b matches the word boundary. A regexp '\bnf\b' does exactly what the OP wants.

nezachem 616 Practically a Posting Shark

Hello everyone,

I am new to assembly, and I am trying to learn it. I was given a book by one of my professor to read over the Holidays unfortunately the book assumes basic knowledge in Assembly (BTW, the book is "See MIPS run linux") I just have some basic questions to clear the picture:

* What is the difference between MIPS assembly and x8600 assembly??

They have absolutely nothing common.

do they use the same debugger ?

Yes and no. Properly configured gdb debugs both, yet it uses different backends.

* When someone says "MIPS architecture" does this have to do with the processor used??

Yes.

* what is the best way to start programming in assembly (I usually use emacs or xcode to code in c/c++ would it work with assembly??)

Let's not start vi-emacs holy war.

* Finally, is it true that some games are programmed using assembly to make it run faster :D (it is a bit between me and one of my friends LOL)

Maybe there are some (I don't know any), and if there are they are definitely not in a mainstream.
These days using assemby doesn't give any performance gain, and badly hurts both portability and time-to-market.

nezachem 616 Practically a Posting Shark

"\bnf\b"

nezachem 616 Practically a Posting Shark

Yeah...and that could go recursively i guess. :)

It can, but why?

Edit: Why bother about efficiency? Even if we were still on Pentium 1's, for such a small scale project, it really wouldn't matter.

Consider it a common courtesy. The program is not alone in the system. It shall consume as few resources as possible. Besides extra cycles burned contribute to a global warming.

Seriously, even in a small project you may face surprises. Efficiency is not just speed and/or footprint. It is also a way to handle data correctly. This is especially important when dealing with floating point values. Each arythmetic operation results in a certain lost of precision. A wrong evaluation schedule may make such loss intolerable. The Horner schedule I mentioned reduces a number of operations dramatically therefore giving much better precision and less risk of underflowing.

nezachem 616 Practically a Posting Shark

There must be a load of open source WAV readers around. In case you don't want to dig into other people's code, here is a brief description of a WAV format.

I guess that's enough to start with. If you have more specific questions, do ask.

nezachem 616 Practically a Posting Shark

>> assuming I understand them

Yes, but instead of asking the user for the number N; N has to be
the sum from 2^0 -> 2^50. I though the instructions were clear enough, especially with the examples.

So the missing link in Narue's code is the summation?
Well then let's start with a few observations:
The sum itself is equal to 2^51 - 1. Assuming one decimal digit per byte a) we'd need 15 bytes or so to represent it; b) the Least Significant Digit (*) of 2th power is not zero hence subtraction of 1 is trivial; c) we just need a way to calculate a power of 2.
We can do it in a most straightforward way by means of multiply-by-two method:

int mul2(char * value, int len)
{
    int i, carry;
    for(i = 0, carry = 0; i < len; i++) {
        value[i] = 2 * value[i] + carry;
        if(value[i] >= 10) {
            value[i] -= 10;
            carry = 1;
        } else {
            carry = 0;
        }
    }
    if(carry == 1) {
        value[len] = 1;
        len += 1;
    }
    return len;
}

and call it as in

char data[20] = { 1 }; // "fifteen bytes or so"
    int i, len = 1;
    for(i = 0; i < exponent; i++) {
        len = mul2(data, len);
    }

This works, although for large exponents is highly inefficient. Which leads us to the next challenge:
Write a program which given an exponent N, designs an …

nezachem 616 Practically a Posting Shark
const char *infile = "bigfile.dat";
  size_t bytes_read, bytes_expected = fsize(infile);

Don't you think that fsize better works on a FILE *, rather than char *?

nezachem 616 Practically a Posting Shark

How about if I have like 300 websites? Can you plz help me how should I retrieve all those 300 urls and take the snapshot of each one of them?

I have no idea.
Be more specific please. Where did you get those 300 urls from?

nezachem 616 Practically a Posting Shark

man wget

nezachem 616 Practically a Posting Shark

Value = a0 * x^ 0 + a1 * x ^1 + .... + aN * x^n , run through the array and compute the result.

Just as NB, don't do it directly as written, it is highly inefficient.
a0 + x*(a1 + x*(a2 + ... +x*(a[N-1] + x*aN)))))...))) is a way to go.

nezachem 616 Practically a Posting Shark

Frankly, I did not understand the statement of the problem. The more I read it the more contradictory it looks. Maybe I shall quit drinking.

Can you please translate the following

A multiplied Sum Of digits is the sum of the digits of a number N, in which those those sum of digits, are then multiplied of digits.

into English so that a drunk Russian may understand?

Ancient Dragon commented: LOL :) +25
nezachem 616 Practically a Posting Shark

In your second listing (function definitions) the functions you define do not belong to any namespace. using namespace SALES; merely informs the compiler to decorate referred names. You should put them in a namespace the same way you did in the header file, that is inside namespace SALES {...}

nezachem 616 Practically a Posting Shark
#include "abc.c"

doesn't go together with

abc.c is only available as abc.o (source code not available)

Did you mean to #include "abc.h" perchance? abc.h should contain

extern int a;

Don't forget to delete line 3 in your test-lib.c

nezachem 616 Practically a Posting Shark

OK, now I really see your problem (please disregard my previous post).
Pay attention to the lines 11, 16, 21, 31 and 41. There you assign value, which points somewhere into confbuffer, which content keeps changing, and eventually becomes nothing (try to print both Botnick and Botname at line 17 - you'd be surprised). By contrast, in lines 26, 36 and 46 you convert the value into an integer right away, and the result of conversion stays put.
My recommendation is to deploy strdup, such as Botname = strdup(value); etc.

nezachem 616 Practically a Posting Shark

Why do you go into such complications as newMember->&(*person)->getFullName() , when newMember->person->getFullName() is enough? In fact, not just enough, but even correct.

if the code works correctly

I gather the code doesn't compile, so it is too early to guess how it works. Once you have an executable which you can run, we may start to debug the logic.

nezachem 616 Practically a Posting Shark

All right, here goes a challenge. Please forgive me if it is well-known already. Also, it is not really a programming challenge, but rather a brain warmer (still any code is welcome).

Anyway:

A crew of N pirates is going to distribute a bounty of M doublons according to the following rules:

1. A pirate of a highest rank proposes a distribution.
2. The crew votes on a proposal (one pirate - one vote, regardless of the rank).
3.0 If ayes >= nays, the distribution is approved.
3.1 Otherwise, the attempted distributor walks the plank, and the process repeats from step 1.

Notice that:
- a crew is strictly ordered according to rank
- pirates are greedy: each one wants as much as possible, as long as he stays alive
- pirates are smart and reflective.

Question: describe the distribution.

nezachem 616 Practically a Posting Shark

Watch for spaces around '='.

nezachem 616 Practically a Posting Shark

C++ standard questions:
------------------------------------------------------------------------------------
The C standard states that the maximum bit's in a char is 8

It does not.

, C++ inherits. I believe the standard also states the minimum bits in a char is 8, is this correct?
Am I correct in assuming a char will this always be 8 bits?

No.

I've never seen sizeof(char) report anything but one byte. Does the standard state anywhere a char must be one byte?

No.
It says sizeof(char) is 1. It also says that char is at least 8 bits.

(I'm pretty lame at reading standards... I just about hacked OpenGL)

sizeof() cannot be <1, if a char IS 8bits, does that mean the system byte must also be 8bits? or does it only use the first 8bits of a larger system-byte?

If both the above questions are true, does that mean that Char = 8bits = one byte on all implementations?

No.

--------------------------------------------------------------------------------
Platform questions:

I'm currently calculating the endianess and sign bit location for ALL data types:
EG: Int_Endian, char_endian, etc...etc...etc:
Has anyone actually ever heard of a system (any system) that has a c++ compiler and stores data types with different endians?

There is (and I mean there are) a system with a c++ compiler which has a memory addressing scheme 1-4-3-2. Go figure an endianness for 16-bit values.

Can I reasonably expect the system to use the same endian and sign-bit-location for all data types?

Answer a question above.

nezachem 616 Practically a Posting Shark

newMember->person is a pointer. You cannot apply a dot to it. Dot is only applicable to instances. Replace a dot with an arrow in all offending lines, as in newPerson->fullname That was purely syntactical. The last error (which I believe refers to line 42 in the posted code) needs more attention. What are you trying to do there, in plain English please?

nezachem 616 Practically a Posting Shark

I have this code. I want to update the writes immediately to log file before closing the file (because my program might get hang and I have to exit it by ctrl+c so fclose would never be called). The code is:
...
but even though I force it to halt at line 15 so that I can view the log file from another console, I do not see any output written when opening the file. I am not sure why it is not working as expected.

Need some help here.

Thanks.

fflush ejects unwritten data from the stdio buffers, and causes an underlying write system call. The further events in the data life cycle are in the hands of OS and beyond the reach of the application (BTW, which OS you are using?).
In the long-running applications with sporadic logs an open-write-close sequence is usually recommended. There's also a really dirty fflush(fp); close(dup(fileno(fp))) trick.

PS: you may try to register fclose in an event handler for SIGINT.

nezachem 616 Practically a Posting Shark

Third, except for line #1 your code is written in classic C style, not C++ so posting to the C board may get you more responses.

Not so. pop() argument is passed by reference, which addresses your seventh bullet.

printf("%s", cast);

Just to avoid a possible confusion.

nezachem 616 Practically a Posting Shark

I'm unsure what you mean, can you explain more?

First, explain me what, in your opinion happens at the lines 49 and 50 of your code:

cout << "Sorted values are: " << insertionSort << endl;
	cout << "Median = " << median << endl;
nezachem 616 Practically a Posting Shark

Hi, I'm trying to write a console program that will sort and find the median of numbers that are given in a text file. The text file can have ints or doubles.

The problem I'm having is outputting the median and the insertionSort functions. I think that they are failing because I did something wrong with either the vector or templates or both as it is my first time writing code using both of those.

Any insight is greatly appreciated.

template <typename T>
void median(const vector<T> & values) ;

template <typename T>
void insertionSort(ifstream& in_file, vector<T>& a_values);
...
	cout << "Sorted values are: " << insertionSort << endl;
	cout << "Median = " << median << endl;

Your assumption is wrong. Your insertionSort and median are functions. You never call them. You just output their respective addresses.

nezachem 616 Practically a Posting Shark

Use a debugger. Set a breakpoint at line 122. Run. Initialize your tree with 1, 2 and 3. Step few times, enter 4 when prompted. Step, step, step up to line 129. Step again. Get surprised. Ask yourself how it is possible to get where it gets you. Solve the problem. Appreciate a debugger.

nezachem 616 Practically a Posting Shark

anyone can help me in this?

Did you read my comments?

As I said, you need at least two things:
1. Check the speck and find out how to move cursor to an initial position at the second line.
2. Write a function to print int into an array of chars (maybe kiel libraries already have it), apply it to hours and minutes and display the result accordingly.

I'm kinda confuse in how it works.

I have no idea how your LCD works, and I am not familiar with the current set of kiel libraries. You have to do it yourself.

nezachem 616 Practically a Posting Shark

There's a number of major problems with your code.

I'd highly recommend you to redesign it according the following guidelines:
1. Create a function int make_step(int prob) returning either 1 or -1. Try to understand what rand() does, and how to calculate directions given the probability of walking to the left (so far you don't seem to understand it).
2. Create a function walk(int startpos) returning single walk data. It should continuously invoke make_step to update a position until either a home or a pub is reached.
3. Create a function void simulate(int startpos) which will call walk for 100000 times accumulating the data, and print the statistics.
4. Call simulate for startpos from 2 to 7.

nezachem 616 Practically a Posting Shark

What I would like to try now is to only create a directory for the day if it does not exist. I thought I could use the && command but then realized I might need to use an if then statement.

I wouldn't recommend it. There's no harm in creating an existing directory other than an error message, which is easily suppressed with -p option. Testing complicates the script and in pathological cases may lead to a race condition.