nezachem 616 Practically a Posting Shark

Nothing in the assignment says that you have to print them as decimals. Just print them as hex. You may want to clarify it with your professor though.

nezachem 616 Practically a Posting Shark

To correct a confusion: math.h is a header. A library (that is, implementation) is libm.so in unix world, and something similar in windows.

You may inspect the source code of libm by looking at the netlib e.g. (which is pretty standard implementation). Maybe you will figure out how to optimize them. Notice however that such code primarilly targets microcontrollers; decent workstation processors all have hardware accelerated math.

nezachem 616 Practically a Posting Shark

I have a nice little bit of OLD code that I use to count the number of bits, and I have adapted the idea. [Note I didn't write the original idea of using 0333 and 0111, but I do not know who did].

unsigned int uCount = MyInt
    - ((MyInt >> 1) & 033333333333)
    - ((MyInt >> 2) & 011111111111);
  
   result=(uCount & 1);

You seem to miss the very important operation here:

uCount = ((uCount + (uCount >> 3)) & 030707070707) % 63;

after line 4.

nezachem 616 Practically a Posting Shark

> The issue being, I can't find any info on the bc/dc utilities

Did you try typing info dc (and/or info bc ) at the command prompt?

nezachem 616 Practically a Posting Shark

When this library is loaded by the host application at runtime and this function is called, is the returned pointer pointing to some place in RAM or to the binary file on disk?

Pointers do not point places in RAM. The are pointing into the address space of the process. Portions of the address space are mapped in and out of the physical RAM as the process execution goes on.

Is RAM ever involved in this situation other than storing the pointer itself?

Of course. The processor may only operate on data which are physically present in RAM.

If it does eat up RAM, would closing the library connection after the host program is done with this function release that memory?

Most likely, yes. As Narue said already, test it on a target system.

nezachem 616 Practically a Posting Shark

got many issues

So what are the issues?

nezachem 616 Practically a Posting Shark

Build a complete application with for debugging. Load it into a debugger. If it is gdb, type b main at the prompt, and then run . Once gdb hits the breakpoint, it will display source file and line number. Adjust for other debuggers accordingly.

nezachem 616 Practically a Posting Shark

Check out http://eathena-project.googlecode.com/svn/trunk/src/common/core.c. Also notice how core.o is get linked (http://eathena-project.googlecode.com/svn/trunk/src/char/Makefile.in):

COMMON_OBJ = ../common/obj_all/core.o (and a bunch more common objects)
...
char-server: obj_txt $(CHAR_OBJ) $(COMMON_OBJ) $(MT19937AR_OBJ)
	@CC@ @LDFLAGS@ -o ../../char-server@EXEEXT@ $(CHAR_OBJ) $(COMMON_OBJ) $(MT19937AR_OBJ) @LIBS@
nezachem 616 Practically a Posting Shark
struct VALUE * new_VALUE(char type, char *value){
    ...
    val->VALUE=value;
    ...
};

struct llist * l_insert_H(struct llist *ls, char type, char * value, int status) {
    ...
    struct VALUE *val;
    val= new_VALUE(type, value);
    ...
};
main (int argc, char *argv[])
{
    ...
    TKN Token;
    ...
}

You have only one instance of TKN in your program. That is, every val->VALUE points to the same instance of TKN.String .

A simple fix would be

val->VALUE=strdup(value);
nezachem 616 Practically a Posting Shark

Your link doesn't work.

Sorry. This is a correct one.

nezachem 616 Practically a Posting Shark

Unions is a poor man's way to express the idea of polymorphism. See for example a definition of X Windows event and related API.

nezachem 616 Practically a Posting Shark

OK, I did the tests.

Of course entering the directory with cd does nothing (and I was wrong claiming otherwise). Only a default path of the process is changed.

On the other hand, any access (like ls ) does change the atime , which is immediately noticed.

nezachem 616 Practically a Posting Shark

i put all the header component in one structure. but still the same :(

typedef struct bmpfile_header {
	uint8_t magic1;
	uint8_t magic2;
	uint32_t filesz;
...
} BITMAPHEADER;

Of course. filesz is still naturally aligned at 4 bytes, which requires padding.

what i don't understand is, it works as i expected when it reads from a bitmap file. but not when writes.

You (correctly) read data very carefully, field by field. You shall write the same way you read.
It is very tempting to avoid padding issues with pragma pack (or __attribute__(align) , depending on a compiler). The result will be highly nonnportable, with the whole spectrum of problems from build failures to runtime faults.

nezachem 616 Practically a Posting Shark

The compiler aligns BITMAPHEADER at a 4-byte boundary. Since MAGIC occupies only 2 bytes, the compiler (when laying out the image structure) inserts 2 bytes of padding between magic and head .

nezachem 616 Practically a Posting Shark

F_NOTIFY is a dnotify feature. I referred to inotify.

PS: I have to admit, I didn't test it myself; let me try it as soon as I get to a linux box.

nezachem 616 Practically a Posting Shark

> I don't know of a way to get notifications when someone enters it

Monitor the parent directory. Entering the target directory modifies atime, so watching for IN_ATTRIB pretty much accomplishes the task.

PS: of course, nobody knows who did the access...

nezachem 616 Practically a Posting Shark

Notice that the blocks of code at lines 30-71 and 72-113 are nearly identical. The only difference is that "*" and "o" are swapped. Create a method doMove(String title, String self, String other) , and use it as

for(;;) {
        if(team) {
            doMove(name, "* ", "o ");
            team = false;
        } else if(team == false) {
            doMove(opo, "o ", "* ");
            team = true;
        }
    }

Not only your code becomes twice as short (which means twice less maintenance), you may immediately realize that the team variable is redundant. Really, the game loop becomes

for(;;) {
        doMove(name, "* ", "o ");
        doMove(opo, "o ", "* ");
    }

BTW, you need a way to detect an end of game situation and break the loop.

Now, let's get into the doMove itself. Notice that you test board[a][b] in each clause. Again, a redundancy must be eliminated:

if(board[a][b].equals(self) {
        ... Keep processing the move ...
    } else {
        System.prinln("invalid input");

}

And last but not least, you allow horrible violations of rules.

nezachem 616 Practically a Posting Shark

Something similar to

for filename in *; do mv $filename `echo $filename | iconv  -f UTF8 -t ANSI`; done

Warning: the above will fail badly if the filenames contain spaces. Tweak accordingly. Test with echo instead of mv first.
PS: I am not sure that ANSI is a correct encoding name (isn't it ISO-8859-1?). In any case, see iconv --list output.

nezachem 616 Practically a Posting Shark

Just do the same math: In any case, guests * cost_of_chicken must be spent. The rest, that is budget - guests * cost_of_chicken may be used to pay an excess price of steak, that is price_of_stake - price_of_chicken.

steaks = (budget - guests * cost_of_chicken) / (price_of_stake - price_of_chicken)

Am I missing something?

nezachem 616 Practically a Posting Shark

No. chdir() understands relative paths.

nezachem 616 Practically a Posting Shark

The segfault is due to the % at line 61. Escape it as %%num.
To change directory, use chdir().

nezachem 616 Practically a Posting Shark

Short answer: system("cmd /c dir") Long answer: system() expects an executable. dir is not, it is a builtin.

nezachem 616 Practically a Posting Shark

Since you are on a Posix system, the best practice would be to adhere to getopt(). It's a part of libc; no extra libraries involved.

nezachem 616 Practically a Posting Shark

So you have 5 places, 2 states each. Sounds like a set of 5-digit binary numbers. 0 to 31.

nezachem 616 Practically a Posting Shark

> I think this is not homework.
It doesn't matter.
> plus I am only 14
At 14 it could be fun. At 16 it's a routine.
Besides, OP's problems may stem from any possible direction, and I broke my last crystal ball yesterday.
Доброй ночи.

nezachem 616 Practically a Posting Shark

Please show us what you have, then we may try to direct you towards your goal.

nezachem 616 Practically a Posting Shark

1. Download and install a WDK.
2. Study the documentation and samples.
3. Find a datasheet for the device you want to drive.

After that a driver for a mouse-class device is a matter of one week.

nezachem 616 Practically a Posting Shark

Did you try CUDA?

nezachem 616 Practically a Posting Shark

I took a quick look, and as far as I can tell, your program can't get past line 33 because the only way out of your while loop is via system("exit") (which I didn't even think about until just now, and appears to kill off the CommandPrompt that your program is apparently running in.

No. system() starts a new shell (which in turn executes exit command and immediately exits). Essentially system("exit") is a very expensive no-op.

nezachem 616 Practically a Posting Shark

The MSDN is very clear: the data buffer is an in/out parameter, that is

The plaintext in this buffer is overwritten with the ciphertext created by this function.

Your pointer is pointing to a read-only string literal. Besides, keep in mind that a ciphertext may take more space than the plaintext. It is always a good idea to call CryptEncrypt twice, first with a null data pointer to figure out how much space is required, then do an actual encryption with the buffer large enough.

nezachem 616 Practically a Posting Shark

PKC is inherently slow. If performance is an issue, you may want to consider hybrid approach. Use PKC at the handshake phase, to securely exchange session keys. Then encrypt the payload with a symmetric algorithm.

nezachem 616 Practically a Posting Shark

Take a look at GNU plotutils.

nezachem 616 Practically a Posting Shark

Did you look here?

nezachem 616 Practically a Posting Shark

Since you brought it up, I've given it more consideration and concluded that remove_if() should either go away, or be modified to work like C++'s remove_if() algorithm where removed items are swapped to the end rather than physically removed.

Oops. Is swapping (I thought about that possibility and discarded it as frivolous) mandated by stl? (Disclamer: I am not good in C++, I honestly do not know).

There's a fine line between providing enough of a base to make as many people happy as possible, and including the kitchen sink. ;)

Granted.

The only time in my career I needed the generic C vectors, I actually needed them for map() and his uncles. I do not think its existence is justified otherwise.

nezachem 616 Practically a Posting Shark

(hoping you'll buy that excuse). :)

All points well taken.

though I'd lean more toward excluding vector_remove_if() than let the smell propagate into an awkward interface.

Now it begins to sound interesting. Why do you think it is awkward (no I am not an analyst; I am genuinely curious)? Just look at libbfd. That is awkward.

PS: I didn't even started on map() and fold().

nezachem 616 Practically a Posting Shark

Just something obviously intended to be unique. The double underscores are technically stomping on the implementation's name space, but since this isn't a production library, I didn't worry about it. The number is my birthday: November 11th, 1978.

Correct me if I am wrong, but it is scoped in the do-while clause, and therefore unique, regardless of the actual name.

A design decision. Like arrays or C++'s operator[] on std::vector, the index is unchecked. Presumably the client code would check it explicitly if it's not trustworthy.

Still... vector_remove() and vector_insert() do validate indices. vector_at() not validating them looks inconsistent.

The first case handles situations where size is 0, so execution shouldn't get to memmove() there. All of the edge cases should be covered, unless my weekend muddled mind just isn't seeing something. ;)

Again, there's an inconsistency. vector_insert() shouldn't go into a memmove when appending (that is, index == v->size ). OTOH, I don't think that the extra logic is justified at all (unless, as I said, it works around a hypothetical bug in memmove).

I'm not convinced that the library should provide this feature. What's wrong with cleanup_action(vector_at(v, i)) before removal? Further, if that's too verbose, what's wrong with the client defining vector_remove_with() if needed?

I suspect it kills the purpose of the library, especially considering vector_remove_if_with() .

nezachem 616 Practically a Posting Shark

Ideas? Sure. There are a number of ways to implement a library interface such that it's easy to use, understand, and maintain. While not perfect (is that ever the case?), here's one such library I have on hand at the moment to show you.

Questions and nitpicking:

1. What is the significance of __anon_var_19781111 identifier (I understand a need for a temporary - I am just curious about the choice of a name)?
2. Looks like vector_at() shall test the index the same way other functions do.
3. vector_remove() special cases a removal from the end. Are there memmove implementations which fail on size 0?
4. Probably most important. Removal an item gives a user no chance to act upon an item being removed. Did you consider adding a

vector_remove_with(vector * v, size_t index, int (*cleanup_action)(void * item))

interface?

nezachem 616 Practically a Posting Shark
.PHONY: backup
backup:
    @mkdir -p ./backup/include    #make folder (don't complain if it already exists)
    @mkdir -p ./backup/src        #make folder (don't complain if it already exists)
    @mv -fu *.h~ ./backup/include #move header file backups into desired folder
    @mv -fu *.cpp~ ./backup/src   #move source file backups into desired folder

Problem: This works great, BUT ONLY if a file "*.h~" and "*.cpp~" file already exist in Makefile's current directory. I would like this target to move the files if it can, and just be quiet if there are no files to move..

Error Message: mv: cannot stat `*.h~': No such file or directory

Few solutions:
1. (dirty) Redirect error message (and precede the commands with a dash (which makes make to ignore an error)):

-@mv -fu *.h~ ./backup/include 2>/dev/null

2. (clean) Be explicit:

backup/include/%.h: %.h~
    @mv $^ $@
backup/src/%.cpp: %.cpp~
    @mv $^ $@

PS: I am not sure why do you keep .h and .cpp together in the current directory, yet want them in separate backup directories.
3. (best) Use source control as Mike suggested.

nezachem 616 Practically a Posting Shark

I'm sure that changes things entirely.

Not really. A filename surely changes (from /dev/ttyS0 to COM1), and open() becames CreateFile(). Instead of tcsetattr there is IOCTL_SERIAL_SET_DCB.

If worst comes to worst, there's always an SFU; more or less supported.

nezachem 616 Practically a Posting Shark

You are correct about the regular expression. However, the OP doesn't match any particular string from the list. He needs to read the list "vertically", top to bottom, extracting exactly one letter from each string, in such a way that the resulting string would match the pattern.
That is how AAC in his example is formed: A from [3], A from [4], and C from [5].

Honestly, I do not see any hope for a more efficient approach than OP described.

nezachem 616 Practically a Posting Shark

I don't know. I'm starting to think I may have imagined something

I think the confusion comes from the overcommit feature of some OSes. Indeed, memory allocation routine may just reserve the address space, and postpone actual mapping until the first access. So an object with the trivial constructor may remain in the aetherial state for a while. However, new would execute exactly when it is called.

mike_2000_17 commented: that makes more sense. thanks +14
nezachem 616 Practically a Posting Shark

AFAIK, it comes from the Cold War times. Then there were superpowers (USA and USSR), developed countries, and the third world.

nezachem 616 Practically a Posting Shark

When using htonl I still get garbage written to the network. ;(

Of course. First sort out the sizeof(buff) issue.

nezachem 616 Practically a Posting Shark
char buff[sk.sz];
		fread(buff, sizeof(buff), 1, fp);

You seem to believe that sizeof(buff) equals to sk.sz . It is not.

As a side note, always convert your longs with htonl() prior to transmission.

nezachem 616 Practically a Posting Shark

You seem to be working with linux. If so, the best way is to avoid outb() and friends. Open /dev/ttyS0, and write to it just like to a regular file. Do not forget to configure the protocol (baud rate, parity, stop bits, etc) with tcsetattr.

See details here.

nezachem 616 Practically a Posting Shark

One fairly obvious problem is at lines 14-15. The way it is written it means that a (phony) target classes depends on nothing, and the recipe is a very strange command. You want classes to depend on the list of class files with no recipe.
Join those two lines together.

nezachem 616 Practically a Posting Shark

At line 42 you call matrixCofact as if it returns the minor's determinant. I recommend to (a) make matrixCofact return double, (b) get rid of its third parameter (you don't use it anyway), and (c) change line 50 to return det . Of course, det should be just double (not a pointer).
PS: minor->elements at line 52 is wrong. It should be mat->elements[0].
PPS: You probably know that it is one of the least efficient algorithms.

nezachem 616 Practically a Posting Shark

It is practically the same design as 4-to-1, with 8 data lines and 3 control lines.

nezachem 616 Practically a Posting Shark

The check is not unnecessary (*), but it is plain wrong. An address field of the EOF record is not necessarily all zeroes, so the checksum is not necessarily FF.

(*) This check helps to determine the integrity of the file. However it only makes sense if every other record is also tested against the data length, checksum, record type, etc. My recommendation is to make all these tests while reading the file, byte by byte.

nezachem 616 Practically a Posting Shark
int a[10000]={0};

Constraints :
1 <= N <= 100000

Most likely the fault is when N exceeds 10000 you've allocated.