nezachem 616 Practically a Posting Shark

Lines 16-19: you allocate just one byte per each variable. Then you copy some substantial strings there. After that all bets are off. Fix the buffer overflows first, and then see if the problem persists.

Salem commented: Bingo! +19
nezachem 616 Practically a Posting Shark

Banned at Google?

nezachem 616 Practically a Posting Shark

Shouldn't it have stored the pertinent values into itself (inside the loop)?

It is global all right, but it isnot global enough. It is global only within the process.
The parent initialize it to all zeroes. Each child gets its own copy initialized to zeroes. Each child puts some values to some slots - and it does not affect the copy owned by a parent.

What does it matter if the child is alive or dead at that point?

Try an experiment:
1. Comment out line 34 (a kill one) and
2. Modify line 43 to

cout << getpid() << ": " << pid_array[i] << endl;

and see what each process thinks about a state of pid_array.

halluc1nati0n commented: Great insight into the answer +1
nezachem 616 Practically a Posting Shark

Are you guys on autopilot again? Beg to explain how null termination is related to the OP problem.

The real problem is that read_string doesn't return anything when it should.

nezachem 616 Practically a Posting Shark

There is something wrong with an answer to the problem 4. Hint: an answer to the problem 3 is correct.

jonsca commented: Yup. I glazed over it! +2
nezachem 616 Practically a Posting Shark

The only thing which comes to mind is to use handles (aka descriptors). The handle-based code does not expose a struct list in any form. An init function returns an opaque handle instead. Of course it needs to maintain an internal registry of allocated handles and a handle-to-list map.
As an example of such approach look at the file descriptors and their open/read/write/close system calls.

nezachem 616 Practically a Posting Shark

This is definitely a wrong venue. You need to ask lawyers in your jurisdiction, not programmers all over the world.

According to my belief system, in the afterlife a keylogger writer will share a cubicle with a spam operator and a product manager.

sknake commented: agreed +0
nezachem 616 Practically a Posting Shark

PIL does not support alpha in BMP files. You need to strip it yourself. Something like (warning: untested):

img = Image.open("file.png")
r, g, b, a = img.split()
img = Image.merge("RGB", (r, g, b))
img.save("file.bmp")
nezachem 616 Practically a Posting Shark

First of all, it's not end1 (with number 1) but endl (with a letter ell), short for endline.
Second, I really doubt that "Teach Yourself C++ in 21 Days" will do you any good.

tux4life commented: Exactly. +6
nezachem 616 Practically a Posting Shark
int counter;

You need to initialize it to 0.

Nick Evan commented: Nice catch, I should've seen that :) +12
nezachem 616 Practically a Posting Shark

First of all, in C you cannot compare strings with comparison operators. They only compare pointers, not the string data. You must use strcmp , as in strcmp(*mid, sample[0]) != 0 .

Next, I am afraid that dict are not what you think they are. They are dict array values, that is character pointers, which point to a more or less random locations. Each is valid, points a particular word, but the arithmetics on them makes no sense, and will cause crashes. What you want is dict array locations, that is &dict. Now the warnings will go away.

Beware that your code may try to access dict[20], which is beyond the array.

Finally, I would highly recommend to restructure your program a little bit.
A. read_words and read_text are in fact the same function; they just fill up different arrays. Get rid of one of them.
B. Do not pass the whole sample array to comparison routine. It only needs one word at a time.
C. comparison is a misnomer. It should be called search .

nezachem 616 Practically a Posting Shark

A single computer may run a bunch of network applications simultaneously. Each incoming network packet must be routed to a particular one. Since the network layer has no idea of applications, the routing is done by means of ports. An applications (say, a server) binds its socket to a specific port, and a peer uses that port number as a part of destination address, so that the full address is ip:port, where ip identifies a computer, and port identifies an application (a socket, in fact) within that computer.

Ports are numbered from 0 to 65535. Some of them are assigned to specific servers. Everybody knows that port 80 is assigned to http server, port 22 to SSH etc. For a complete list of port assignments look at the IANA page.

Hope it helps.

nezachem 616 Practically a Posting Shark

Yet another buffer overflow, I suppose. How much space did you allocate for char buffer ?

nezachem 616 Practically a Posting Shark

If neither cygwin nor PowerShell is an option, you can try to play with FOR /F . Look here for examples.

Salem commented: Beaten ;) +18
nezachem 616 Practically a Posting Shark

Look closely at line 26. You read one character, whereas user entered two of them: don't forget that she hit enter. This enter is consumed at line 18 next time around, which results in an empty username.

PS: do not use ascii codes in comparisons.

nezachem 616 Practically a Posting Shark

A simple answer: you put 3 bytes into a 2-byte array.

What actually happens:
The arrays are allocated at the stack, next to each other, in order year/month/day (from lower addresses to higher). month[2] is the same as day[0]. A classic buffer overflow.

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

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

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

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

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

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

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

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

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

My problem is in my void check_name() function... the function that checks if the name is in the list and then displays it as well. When the program runs for some reason it only works for the first set of names (the #1 boy and girl) but in an infinite loop.

void check_name()
{   name *strt;
    strt = start_ptr;
    cout << endl;
          
          for (name * strt = start_ptr;strt->nxt !=NULL;strt=strt->nxt)
          {      
                if (enter_name == strt->boy_name && enter_name != strt->girl_name) {}
                // etc
          }
}

In this code, the next search starts from the point where the previous search ended. You need to start each search from the very beginning of the list.

This mistake stems from the wrong design decision: the function that checks if the name is in the list and then displays it as well is a bad function. Split the functionality into "find the record" and "display the (found) record".

nezachem 616 Practically a Posting Shark

OK. One step at a time.

char *ptr = "String";
	char arr[]= "Array";
	*ptr ='T'; // behaviour is undefined

ptr points to a string literal, which resides in a read-only section of your data. An attempt to modify it results in segfault, GPF or something else depending of the platform (it may even succeed if a memory protection is not implemented)

arr, however, is allocated on a stack and is just initialized from the literal. This memory is perfectly writable.

arr = ptr; // not allowed

Arrays are not pointers. The are "same" only as function arguments.

printf("Hello" "World"); // HelloWorld

The preprocessor does concatenate strings, that is right.

printf("%s%s","Hello" "World"); // HelloWorld(someGarbage)

You pass one parameter (the concatenated string) and ask to print two.

nezachem 616 Practically a Posting Shark

Pay attention to lines 48 and 49.
At line 48 you print (i, j, k) as soon as they sum up to x, regardless of their relative primarity. Then at line 49 you test their primarity - and do nothing with the result.
You should print data only if the test at line 49 succeeds.

By the way, a loop at line 47, along with test at line 48 just waste processor cycles. The value of k is known right away. Do you see what I mean?

coolfriends commented: Thanks a lot +1
nezachem 616 Practically a Posting Shark
new

Awww it was a C forum not C++
I shall be dragged in the slime and the mud.

jephthah commented: Christ I know you can't hear me / But I only did what you wanted me to / Christ I'd sell out the nation / For I have been saddled with the murder of you / I have been spattered with innocent blood / I shall be dragged through the slime and the mud. +5
nezachem 616 Practically a Posting Shark

There are three things in your code which require attention.
First, buttonstatus is lost as soon as VariableDialog.apply returns. To keep this value, simply return it:

def apply(self):
      buttonstatus = self.status.get()
      return buttonstatus

Then, to get the value you are interested in, call the apply method: status = [I]something[/I].apply() Final question - what is this something? It must be an instance of VariableDialog class (because it is where apply() is defined). Notice that you already created this instance at line 12 of MainScript. You just need to remember this created instance; then you may call its methods:

dialog = ChildScript.VariableDialog(master)
      # From right here, I would like to be able to print the value of 'buttonstatus'.
      status = dialog.apply()
nezachem 616 Practically a Posting Shark

Thanks Nezachem! I have changed quite a lot in the code, and now it does work, with a few exceptions unhandled (like segfaults when getting a permission denied), but those were not mentioned in the assignment anyway.

My main problem was with line 6, where I changed char *com[] to char* com[50], and that started working. I still have no idea why, this being far from my area of expertise, but the girl says she knows why, and that's good enough for me :)

strtok() was a requirement for this assignment, as well as execv(), can't do much about it.

I'm going to dwel on the man pages for wait() now, posting the current working version, in case you have the time to have a look and suggest improvements

I am glad I helped. Few comments:
1.

tempcmd=cmd; //assign to temp variable, so strtok doesn't ruin cmd

doesn't do what the comment claims. The actual string containing cmd remains the same - it just gets accessed via another pointer - and strtok happily ruins it. What you need to achieve the stated goal is to

strncpy(tmp, cmd, sizeof(cmd));

2. Your path-finding logics seems broken. The code sequentially tries to run the command from each path component. Obviously, most of the times the command is not there, resulting in a "No such file or directory" error. Through my crystal ball I can see that your test at line 72 does not catch it. This is because in C …

kvprajapati commented: Great! +6
nezachem 616 Practically a Posting Shark

Thanks, but the article uses execve, which is not an option for me in this case.

I was just looking for an explanation for line 46, 52 and 54 in my code

First of all, what difference does this little 'e' make?

Second, it is not a C question, but rather Unix one. To help your GF you need first to understand the unix process model.

Third, thou shall not strtok.

Now, for your questions.
Line 46: a function from the exec family does not return if succeeds. If it does return it means it failed. This is what a printf is supposed to inform the user about. Keep in mind that the way the code is written, a status is garbage.
Line 52: a wait function waits for a child process to finish (not quite, but for the purpose of this assignment it is OK to assume so). Here the status tells how did it finish, and the code needs to analyze its value, which it half-heartedly attempts to do at line 54. Do 'man 2 wait' for the WIF* macros.

I hope I am not too late with this. There are many problems with this code I didn't even mention.