nezachem 616 Practically a Posting Shark

Do not use list. Keep your objects in a dictionary indexed by coordinate tuple.

nezachem 616 Practically a Posting Shark

getch() returns 26 (ascii for ctrl+z, which indicates the end of input in Windows)

That's a very usual misconception. First of all, ctrl+z is only significant for text mode streams. Second, for text mode streams, ctrl+z is handled by the driver. It is the driver who encounters ctrl+z, and in response it closes the stream. An application would never read ctrl+z; it hits an end of file instead.
For a binary mode streams, ctrl+z is an ordinary character.

nezachem 616 Practically a Posting Shark

class

It's a C forum.

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

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

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

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

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

"\bnf\b"

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

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

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

this is the error i'm getting.
g++ main.cpp
g++ universityperson.cpp

When you invoke g++ with no options, it will try to make an executable. What you need is an object file.
In all your %.o rules (that is, everywhere except UniversityPerson) change g++ to g++ -c . A -c option stands for "compile only", that is produce an object file, to be linked later.

//makefile

UniversityPerson : main.o universityperson.o employee.o academic.o faculty.o   \
teacher.o administration.o support.o student.o
        g++ -o UniversityPerson main.o universityperson.o employee.o academic.o\
 faculty.o teacher.o administration.o support.o student.o

main.o : main.cpp universityperson.h
        g++ [B]-c[/B] main.cpp

universityperson.o : universityperson.cpp universityperson.h
        g++ [B]-c[/B] universityperson.cpp

employee.o : employee.cpp employee.h
        g++ [B]-c[/B] employee.cpp

academic.o : academic.cpp academic.h
        g++ [B]-c[/B] academic.cpp

faculty.o : faculty.cpp faculty.h
        g++ [B]-c[/B] faculty.cpp
teacher.o : teacher.cpp teacher.h
        g++ [B]-c[/B] teacher.cpp

administration.o : administration.cpp administration.h
        g++ [B]-c[/B] administration.cpp

support.o : support.cpp support.h
        g++ [B]-c[/B] support.cpp

student.o : student.cpp student.h
        g++ [B]-c[/B] student.cpp
nezachem 616 Practically a Posting Shark

> How would I fill a two-dimensional array up with numbers
Exactly the way you do it.
> But when I try to print it out it comes up with wierd numbers I printed with:
If you give us more context, we might spot a problem.

nezachem 616 Practically a Posting Shark

The file contains binary

if((cfPtr = fopen("Error Pattern 2.dat","r") ) == NULL)
					fscanf(cfPtr,"%d", &Array[j]);

Binary file needs to be opened in binary mode ("rb"), and may not be read with fscanf(). Use fread() instead.

Beware the portability issues.

nezachem 616 Practically a Posting Shark

You did not use a debugger.

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, now I get what you doing.
Let me reiterate: use a debugger. It is entertaining and enlightening. You will immediately see how do you actually print. Hint: lines 33 through 37 have only one chance to run.

nezachem 616 Practically a Posting Shark

Frankly, I did not get what you are trying to do, but maybe that's just me.

Hello,

The above code gives me values for only one text file and then goes in to an infinite loop. The other text files are generated though as empty files.

Once you completed an inner loop once, you have read everything from the file, that is reached the end of file, that is all subsequent reads do not produce any data. Either fopen and fclose your filename in each iteration, or rewind it (in each iteration, of course).

nezachem 616 Practically a Posting Shark

I have the following code which works on the .txt file
...
Can anyone please help me how can i avoid the memory leaks here

Frankly, I don't see how it may be freed at all. Judging from the code, you build a list of chunks, and besides that each chunk is referenced from keyword. The keywords themselves, as far as I can tell, are only accessible through the chunks. Is it what you have intended?
If so, don't call it memory leak. If not, describe your intended data structure design and we can figure something out.

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

Is comctl32.lib added to your project?

nezachem 616 Practically a Posting Shark

Heya folks. I'm trying to write a BMI calculator, but I'm missing something.

Splint tells me I have a parse error before the scanf, but I'm not seeing it.

#include <stdio.h>

int
main() 
{
	float height, weight;
		
	printf("Enter your height in inches and weight in pounds: \n");
	scanf("%f%f", &height, &weight);
 	float bmi = (weight/(height*height));	
	...

You have a variable (bmi) declared not at the top of a block.
This is valid only in a c99 domain; most likely splint assumes an older standard.

nezachem 616 Practically a Posting Shark

That code compiles but I get a wicked error that I have never seen before. What's wrong with this?

dp = opendir (".");
  if (dp != NULL) {
      while (ep = readdir (dp)){
...
      closedir (dp);
      }
  }

Do you see anything funny about this fragment?

nezachem 616 Practically a Posting Shark

I can print all the files and directories like this

#include <stddef.h>
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>

int
main (void) {
  
  DIR *dp;
  struct dirent *ep;

  dp = opendir (".");
  if (dp != NULL) {
      while (ep = readdir (dp))
        printf("%s\n", ep->d_name);
      closedir (dp);
  }
  else
    perror ("Couldn't open the directory");

  return 0;
}

But how do I do this?

If (file is a sub directory)
open it, and print those files.

First of all, you need to be able to tell files from directories. I am not sure if a dirent has such information; in any case you may stat the name:

struct stat statbuf;
stat(ep->d_name, &statbuf);
if(S_ISDIR(statbuf.st_mode)) {
    // It is a directory
}

Second should be obvious: once you detect a directory, recurse into it.

nezachem 616 Practically a Posting Shark

You must realize that in C strings are not first class citizens. There's no support for them in the language. There's no operator to compare them. There's strictly speaking no such thing as a string.
What is there is a memory region occupied by bytes, and a pointer to that region. You may think of it as an address of the region.

The comparison operator '==' compares just those addresses.

Now notice that in your program there are two distinct memory regions: one called "name", and another one, where lives the string literal "Amanda". They are distinctly different; they appear at the different addresses. Of course the comparison fails.

What you really want to do is to test that those regions contain the same data. For that, you need to compare them byte by byte. You may do it manually (I bet you know what the for loop is), or call a library function such as strcmp, which exists specifically for that purpose.

nezachem 616 Practically a Posting Shark

thanks for your help but i guess i am not understanding it clearly..
i would really appreciate if you could show me in code...

thanks

Something along the lines of

int k = 1;
int i = N/2 + 1;
int j = N/2 + 1;
while (k < N) {
    int s;
    // going right:
    for (s = 0; s < k; s++, i++, I++)
        arr[i][j] = isPrime(I)? I: -1;
    // going up:
    for (s = 0; s < k; s++, j--, I++)
        arr[i][j] = isPrime(I)? I: -1;
    k++;
    // going left:
    for (s = 0; s < k; s++, i--, I++)
        arr[i][j] = isPrime(I)? I: -1;
    // going down:
    for (s = 0; s < k; s++, j++, I++)
        arr[i][j] = isPrime(I)? I: -1;
    k++;
}
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

The main loop should fill the array (not print it, but just fill) in the following manner:

K steps to the right
    K steps up
    increment K
    K steps left
    K steps down
    increment K

Break the loop as soon as K reaches N.
Of course, each step increments I as well.
A step to the left changes current coordinates (i, j) to (i - 1, j), a step down - to (i, j + 1) etc.
Once the array is filled up, print it in another loop.

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.