tux4life 2,072 Postaholic

>Sorry to all if this is in the wrong forum
If your script is written in PHP, and your question is related to PHP/your script, then I would say that it's in the correct forum.

tux4life 2,072 Postaholic

Only one very important thing when using XOR encryption is, what are you going to do when there are so-called nul-bytes in the file?
nul-bytes are bytes which look like this:

00000000

XORing nul-bytes together with a character from within the encryption key (aka: encryption password), will reveal parts of (or in the worst case: the whole) password.

This will make it particulary easy for John the ripper/a cracker to decrypt the data and steal it.
And that's probably not what you want.

tux4life 2,072 Postaholic

NOTE: Throughout my whole post I assume that bytes consist out of eight bits.

When you use the XOR-algorithm to hash/encrypt your data, there's no need to implement a different way to decrypt your data.

XOR means: eXclusive OR.
As you may know: a normal OR operation requires that either one of both operands is true, to make the result of the operation true, but if both operands are true, the result will be true as well. Only if both operands are false, the result will be false.

It's a bit different with XOR: if you want an XOR operation to have true as result, only (and only) one of the both operands may be true, if they're both true, then the result will be false, if they're both false, the result is also false, if only one of them is true (and the other one is false), the operation will yield true as its result.

And now a practical explanation on what it means when you apply this approach to bits (that is: apply XOR bitwise):
Say, you have two bytes which respectively look like this:

Byte 1: 10110111 ([I]data to encrypt[/I])
Byte 2: 00001101 ([I]encryption key[/I])

When you XOR both together, you'll get this result:

Byte 3: 10111010 ([I]encrypted data[/I])

Let's assume that Byte 2 was a character from the encryption key, then we can easily decrypt the whole thing by exactly doing the same: (bitwise) XOR both, the encrypted …

mrnutty commented: My first rep++. Thanks for the refresher. +2
tux4life 2,072 Postaholic

So for example I have a 16 (in decimal), I want to place it in the system so that it can calculate the result, so I need to convert it into 0xF (in hexadecimal) so that the system understand is 16(in decimal) and then when for instance I want bit 3 to toggle, it will convert this 16(in decimal) to binary number 1111. And then the third bit counting from right will be toggled and the result will become 1011?

I guess you misunderstood my previous post, wait let me explain it again:
As you know, C++ is a programming language, to make it a bit more complicated: C++ offers support for variables.
When you want to assign a literal to a variable (for all practical purposes a literal just means: a number), you can either do one of the following:
C++ offers built-in support for 3 other bases (which are different from binary): decimal, hexadecimal and octal (I'm not going in depth on octal).
You can directly assign a value from either one of those bases to a variable, no matter from which base you choose to assign a value, first that value is automatically converted to binary.
To assign a decimal value to a variable you just write out the number (in the way you usually do):

int var;
var = 16; // assign the decimal number 16 to the variable

However, if you want to assign a hexadecimal number to a …

tux4life 2,072 Postaholic

I've seen that one and it is so hard to browse with poor descriptions. If that's the best on the web then somebody really needs to document that language in much greater detail like how the php documentation has those huge pages for each function.

Well, that one (the API document) is clear enough for me, once you know what a class does, you can easily figure out what a certain method does, and how to use it.
Of course it assumes that you understand the Java language, that's the price of admission you have to pay.
It's even well structured: you first select the desired package, then you select your desired class, and after that you can see a whole list of methods belonging to that class (with an accompanying description).
You have to keep in mind that the intent of that document is rather for programmers (people who already know the language) than newbies (people who only know tad bits of the language).

tux4life 2,072 Postaholic

Please it's not compiling showing some errors help me to execute.

Well, I need to see the error messages, could you post them all down ?

And also try to explain me line to line what will happen in this program.

Did you actually write this code yourself?

tux4life 2,072 Postaholic
tux4life 2,072 Postaholic

In your previous thread I told you to use code tags, and I provided you a link to the forum announcement, now you're still not able to use them correctly.

Do you also remember what I said about void main() and conio.h ?

tux4life 2,072 Postaholic

Could Someone tell me whats the diffrence between call-by-value with call-by-refference?

Hard time using a search engine?
http://www.lmgtfy.com/?q=pass+by+value+or+reference

tux4life 2,072 Postaholic

Wait, I doubt whether this program will correctly terminate on every machine, it appears that it won't, because you're using void main() , the standard says that you must use int main() and not void main() (void main() is evil!!)

Further you're not using code tags (you should, as described in the forum announcement about code tags, so please use code-tags from now on).

Hmm... What else can I comment on?
Well, you're making use of an unportable library called conio.h but for what purpose? Only to ask for a key press just before the program closes? You could use the getchar() function instead of conio's getch() , so you can make your code portable.

what was wrong in this code, Its taking the username but its not properly taking the input of password.

Well, you want to store a username into a character variable, a character variable is only capable of holding one character, not a sequence of characters. If you want to store a sequence of characters, you should use a character array (aka: C-string), a character array is declared like this:

char username[50];

The above code reserves space for storing a username which can consist out of a maximum of 49 characters (remember: the last character is always used to store the nul-terminator)
Now you can get the username by using scanf like this:

scanf("%s", username);

More info about character arrays and the scanf-function can be found at …

Aia commented: Hard work. But seriously, scanf for reading a string? ;) +18
Salem commented: Another home run, this one's out of the ball park! +36
tux4life 2,072 Postaholic

Hey ggsddu,

Don't you think your reply to this thread came quite late?
(The thread is already dead for over a year)

Another suggestion: Daniweb offers you the ability to wrap your code between
code tags, make use of it, your code will be much easier to read that way :)

Edit:: You must have edited your post (added code tags) while I was writing mine.

tux4life 2,072 Postaholic

My project is all about queue implementation... please write me a code about calculator with queue. tnx.

Here's something essential, start from this and write the rest on your own:

#include <stdio.h>

/*
  Your function declarations
*/

int main(void)
{
   /*
     Your code here
   */
   
   return 0;
}

/*
  Maybe some functions here
*/
ithelp commented: Nice one. +12
tux4life 2,072 Postaholic

I guess you'll find this valuable:
http://www.daniweb.com/code/snippet151.html

tux4life 2,072 Postaholic

That being said I haven't seen any decent documentation for Java. (Not javascript) At least nothing sorted like the php documentation.

http://java.sun.com/j2se/1.5.0/docs/api/
The about 3500 classes of Java 5.0 are covered in here.

tux4life 2,072 Postaholic

Do we need to convert the hex to normal decimal and then based on the decimal and find out how to do it?

Nope, a value in an integer variable is technically stored as a binary value.
For example: whether you assign 16 (in decimal), or 0xF (in hexadecimal) to an integer variable, the integer variable will have exactly the same value (1111).
When you display it using cout, then by default, that binary value will be displayed as a decimal value, but remember that that is only the way how it's displayed.

You just assign the hex-value to the integer variable, and adapt the way I described previously.

tux4life 2,072 Postaholic

this is quite an easy one.....

That's a usual answer when you've not thought too much about the problem.

It's not as easy as:

get [I]first operand[/I]
while(operands present) {
   get [I]second operand[/I]
   get_operator
   result = [I]first operand[/I] op [I]second operand[/I]
}

because that procedure neglects the precedence of operators, but it could of course just be that you find it easy.

Edit::
Want something else?
Invent your own computer language and write an interpreter for it.

tux4life 2,072 Postaholic

Okay, what do you think of writing an expression parser?
That is a program which for example takes an expression as a string, evaluates it and reports the result to the user.

An example:
Input: 5+5*2+1
Output: 16

tux4life 2,072 Postaholic

Then what does this line do?

set the mask to 0xF7 and peform the bitwise AND operation with the variable.

What is the meaning of the 0xF7?

0xF7 is a hexadecimal number, it is the same as 247 in decimal.

But in C/C++ you don't have to convert it or something, you just set your mask to 0xF7 .

You'll probably say: How do I do that?
Well, it's not difficult:

int mask;
mask = 0xF7; /* set the mask */
tux4life 2,072 Postaholic

just wondering.

I actually don't understand your question at all.
I guess question has nothing to do with PHP and it should rather be in the Geeks Lounge (correct me if I'm wrong).

tux4life 2,072 Postaholic

As for STFW - absolutely no clue what it means;)

Just because you'll most likely encounter it again in your first next thread: http://catb.org/esr/faqs/smart-questions.html#answers

tux4life 2,072 Postaholic

In addition to all what has already been said:
No language is perfect, each language has it's advantages and disadvantages.

tux4life 2,072 Postaholic

An example to the question I don't know:

To turn bit 3 of a variable to 0. the correct way is to:

Ans: Not sure how to do but I think I know it involve some thing about Mask and flags.

Short answer: take a value where all bits (except the third) are 1 (the third needs to be 0), this is your mask.
Then you (bitwise) AND it together with the value where you want to set the third bit to zero.

A more detailed explanation on how to 'build' the mask:
As you want to set the third bit to zero, we need to take a value where (in binary) only the third bit is set to one, and all the other bits are 0, there exists such a value, and in decimal it's: 4 (in binary: 0100).
Now you subtract this value from a value where all bits are set to one, you can get this value by just doing: ~0 .
So far your mask looks like: ~0-4 .

A very small description of the ~ operator:
The ~ operator is called the bitwise-NOT-operator, it's a unary operator (just like the logical-NOT-operator: ! ), all what it does is flipping/reversing the bits in a binary value, a one becomes a zero and a zero becomes a one.
So to resume, all what ~0 does is flipping the bits in the binary value of 0 to one, in this …

tux4life 2,072 Postaholic

I don't understand your idea?

You asked:

I don't know the difference between the direct entering value for element of matrix and through the temporary like code before.

Salem answered:

None at all springs to mind.
At least none that matters.

Which means that:
He doesn't see an important difference between using a temporary variable, or directly writing to the matrix.

tux4life 2,072 Postaholic

Having a hard time using Google?
My first advice before starting a new thread is: STFW first!

http://www.learncpp.com/cpp-tutorial/154-uncaught-exceptions-catch-all-handlers-and-exception-specifiers/
(Exception specifiers)

But I suggest you to read the two previous pages first.

tux4life 2,072 Postaholic

Well, why don't you just check out the code snippets section?
Plenty of good stuff about pointers can be found here.

Edit::
The nicest code snippets I've ever seen on this forum, were the ones which you can find here (though they're more about C than about C++, I'd strongly want to suggest you to have a look at them (they illustrate some interesting coding techniques).

tux4life 2,072 Postaholic

To the OP:
Broken dot-key?

As firstPerson said, we need to know exactly how well you know C++, otherwise we'll maybe suggest things which you'll find way to difficult to accomplish using your current knowledge.
So, please make up a list for us (please be as specific as possible), and post it down.

Also useful for us to know is: what kind of applications have you programmed so far? (we'll try to measure your practice), if your list of applications is limited to only a mere "Hello World"-program, then this (your project) will be a big challenge for you.

tux4life 2,072 Postaholic

Well, hard-coding the whole alphabet in your program is possible, but there's another way, without needing to hard-code the whole alphabet in your program, let me describe it:

Input a Number: 5
a
bc
cde
defg
efghi

The above sample run of the program makes me think about the fact that you'll need a char variable for holding the 'current' letter.
First: the current letter is 'a', then it's 'b', after that it becomes 'c', and so on.
When you take this approach, you only need to display alphabet characters, starting from the current letter each time.
What do I also see? Hmm, if the user inputs 5, I see the program prints five lines, so you'll need a for-loop which runs the same amount of times, as the number the user entered (if the user enters 5, the loop runs five times, if the user enters 7, the loop will run 7 times).
Another thing I see is that each time, the length of the line increases with one, in the first loop run, we want the line to be of length 1, in the second loop run we want the line to be of length 2, etc...
You can achieve this by running another for-loop inside the outer for-loop (yes indeed! a loop inside another loop), you let this loop run and set the condition so that it will stop when its index is higher than the outer's …

tux4life 2,072 Postaholic

please help me i cant figure out what codes do i use..

I'm sure you can, when you do some effort:
http://www.daniweb.com/forums/announcement8-2.html

please help me...

Sure, don't take this wrong but I would like to see first that you've at least tried to solve it.

tux4life 2,072 Postaholic

What do you mean by version 3 C? There are only 2 versions made by ANSI/ISO; C89 and C99.

I guess he's using Turbo Crap v3.0 :P

Hi Friends,
I am facing a probelm. The moment I complete a program i C (version 3), it complies successfully. However, the moment I try to run the program it says a Linker error.

Could you provide us:

  • The program which you did try to compile.
  • The complete linker error message.
Salem commented: The "I've got a secret error message and I'm not telling you" award. +36
iamthwee commented: Salem that's not really a secret message. If you want to send him a secret message PM him. But I'm intrigued now, what was your secret message? +23
tux4life 2,072 Postaholic

Actually, an array is a list/set of variables, for example:

int array[15];

The above array reserves memory for 15 elements (of type int) (as all arrays start with element 0, the upperbound of the array is 14 (and not 15))

Let me give you an example on where arrays come in handy:
Imagine, you have to keep track of the scores of students (yes, I see the irony :P), and you have to store scores for about 15 students, then you could either: declare a variable for holding each student's score, or you could create one array containing 15 elements to hold each student's scores.

Using the declare-a-variable-for-each-student-approach, your code would quickly grow in size, e.g:

int score0;
int score1;
int score2;
int score3;
int score4;
int score5;
int score6;
int score7;
int score8;
int score9;
int score10;
int score11;
int score12;
int score13;
int score14;
.
.
.

(and even if you'd put multiple of these on the same line, it would still be pretty clunky, what if for example, you've to a thousand of those?)
Your input procedures would become something like this:

cout << "Enter score for student #1: ";
cin >> score0;

cout << "Enter score for student #2: ";
cin >> score1;

cout << "Enter score for student #3: ";
cin >> score2;

cout << "Enter score for student #4: ";
cin >> score3;

cout << "Enter score for student #5: ";
cin >> score4;

cout << "Enter …
Nick Evan commented: that's a fine example +25
tux4life 2,072 Postaholic

Could you first explain us what your program is supposed to do, and how the -r command line parameter should affect its output, so we don't have to puzzle everything out?

tux4life 2,072 Postaholic

These lines should give you a compiler error:

nop = atoi(number_of_people);
user usera[nop];

C does not allow an array to be declared with an (at compile time) unknown amount of elements. If you want to use dynamic arrays, you should have a look at malloc() and free() What compiler are you using?

Previously I've been able to compile such programs, I guess this has to do with VLAs (=Variable Length Arrays) ?

tux4life 2,072 Postaholic

my intention was to compare two double numbers. Is there any better ideas how I can do that? Because you cant do just
if(a>b) then.....
where a and b are both double.

I guess you'll find this useful:
http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.17

tux4life 2,072 Postaholic

>Whats up with the attitude?
Remove: the h*ll from that sentence :P

tux4life 2,072 Postaholic

Hey firstPerson, where the h*ll do you see in his spec that he has to use a class?

This system should be implemented using structure and array. i am required to develop a structure which contains student details such as Student ID, Student Name, Nationality and Gender.

To the OP:
I already wrote an extensive post about this, which you can find here:
http://www.daniweb.com/forums/post949513-2.html
(Edit 1 and Edit 2 don't apply to your problem)
Also read this one:
http://www.daniweb.com/forums/post949543-3.html
(which contains some corrections)

This is probably enough to get you started, in case it isn't, I strongly suggest you to Google for a tutorial on structures.

tux4life 2,072 Postaholic

which words r creating syntax error??

I said: I understand every word, except your whole post in it's full.

Could you (please) talk in normal English, otherwise you're breaking the "Keep it clean" rule (and nearly no-one is willing to help you then).
(Forum rules)

Further: Can you reformulate your question?
(and post your code as well, use code tags).

tux4life 2,072 Postaholic

Having a hard time in solving logical questions?
http://www.daniweb.com/forums/thread211642.html

tux4life 2,072 Postaholic

I understand every single word in your post (except the words which consist out of one letter), but your whole post raises a syntax error with me (hope I'm not the only one).

tux4life 2,072 Postaholic

-> is called the arrow operator and is often used to access the data members of a structure (via a pointer).
Consider a structure which looks like this:

struct dog
{
  string name;
  int age;
};

Using that structure, someone could write code like this:

dog mydog;
mydog.name = "Lady";
mydog.age = 7;

However, when for example you have a pointer to a structure, you'll have to access the elements in a different way: first you need to dereference the pointer, and then you can access the elements of that particular structure.
An example:

dog mydog;
dog *p;
p = &mydog;

(*p).name = "Lady";
(*p).age = 7;

Parentheses are needed here because the dot operator has a higher precedence than the * operator.
However, there's another way to write that code:

dog mydog;
dog *p;
p = &mydog;

p->name = "Lady";
p->age = 7;

In the above example, p is still a pointer to a dog structure, but now we access the data members of mydog using the -> (arrow) operator.
To resume: both (*p).name = "Lady" and p->name = "Lady" will do exactly the same thing.

tux4life 2,072 Postaholic

Do I just look at your last example and use the ones from before and try and build from there with a string array?

Depends on what you're planning to do with it.
There are two approaches you'll want to consider, you have to pick the one which fits best your needs.
The first approach is just storing the letter for each grade, for example: 'A', 'B', 'C', 'D' or 'F'.
But there's a downside if you use this approach: what if you want to compare two students with grade 'A', to see which one did better?
It won't be possible here, because you only stored the letter which represents a grade (a letter which represents in which range the users score on a particular test was).

The second approach is store each student's exact score, for example: 325, 89, 426, etc. and convert them to their appropriate grades, only at the moment when you need their corresponding letter.
Also this approach has a downside (if you really can call it like this):
Each time when you need the grade in form of their alphabetic representation ('A', 'B', 'C', 'D' or 'F'), you'll have to call a conversion function, which converts the exact score to the letter which represents the grade (you've already code which does this, you could for example put this code in a function, which you could call each time when you want to convert an exact score).

So, …

tux4life 2,072 Postaholic

I just re read both assignments. I think its just making the code I posted above to be able to print the students name with the entered scores using the same 4 scores formula. and using -1 or something similar to end asking for students and display end result.

I guess you want to do something like this, please correct me if I'm wrong:

Welcome to our simple student grades database!
To quit the program and display the results, enter an empty student name.
To stop entering grades for a particular student, enter a negative number.

Enter student name: John [I]<ENTER>[/I]
Enter grade #1: 50 [I]<ENTER>[/I]
Enter grade #2: 325 [I]<ENTER>[/I]
Enter grade #3: 253 [I]<ENTER>[/I]
Enter grade #4: -1 [I]<ENTER>[/I]

Enter student name: Tom [I]<ENTER>[/I]
Enter grade #1: 211 [I]<ENTER>[/I]
Enter grade #2: -1 [I]<ENTER>[/I]

Enter student name: [I]<ENTER>[/I]

The results (listed per student):

----- Results for John -----
Grade #1: F
Grade #2: B
Grade #3: C

----- Results for Tom -----
Grade #1: F

(<ENTER> means that you press the enter key at that point)

tux4life 2,072 Postaholic

So, you need to make modifications to code you created in a previous assignment.
Is it possible to post the whole description of that previous assignment as well?

tux4life 2,072 Postaholic

You could already obtain a whole bunch of updates by simply installing:
Microsoft Windows 2000 Unofficial SP 5.1.2195

Please note that this is a Service Pack, but it's unofficial, which means that it isn't created by Microsoft, read the README before installing it.

After installing this unofficial SP5, you can visit the Windows Update site, and install all other updates (as suggested by superdav).

As I still use Windows 2000 myself (on an older computer), I can confirm it works fine and that I've never had any problems with my installation after installing it, but it's of course your choice.

tux4life 2,072 Postaholic

And....Another approach (maybe not the most efficient one):

bool isAnagram(string str1, string str2)
{
  sort(str1.begin(), str1.end());
  sort(str2.begin(), str2.end());
  if(str1 == str2) return true;
	
  return false;
}

(You'll need to include the algorithm header file, you can do this by adding the following include directive to your program: #include <algorithm> )

tux4life 2,072 Postaholic

Just notice a small mistake in my previous post, I said this:

Let's do that now:
This is the previous code, which only prints scores which are 'set' ('set' means here: the grade is higher or equal to zero):

And this was some related example code:

// Print out a student's grades
cout << "Grades for student: " << stud0.name << endl;
for(int i = 0; i < 20; ++i) {
  if( stud0.grades[i] > 0 ) {
     cout << stud0.grades[i] << endl;
  }
}

But you'll need to modify the if-statement so that it becomes:

if( stud0.grades[i] >= 0 ) { // or > -1
   cout << stud0.grades[i] << endl;
}

You'll have to do this through my whole post.

I also said something like:

Let's start 'building' an array of students (yes, this is also possible), it's not something special, you can declare an array of type student as follows:

Here with:

it's not something special

I meant that it's not different from declaring any other array.

Further I noticed an irritating typo in this:

This example is obviously wrong because it will place the ASCII equivalent if 35 in the array, and not the grade 'F', so be sure that you do a conversion first.

The 'if' has to be 'of'.

tux4life 2,072 Postaholic

What I am not understanding is, is it asking to be able to let the user enter each students name individually and then have it display a list of names with the grades associated with it?

Hmm, smells like you need a structure (often abbreviated as: struct).
structs are used to group related variables into a new user-defined type, let me give you an example, you want to store the student name, together with his grade(s), in that case you could create a structure which looks like this:

struct student
{
  string name;     // to store the student's name
  int grades[20]; // make room for storing 20 grades per student
};

If you only need to store one grade per student, then you can also just replace the array declaration int grades[20] by this: int grade; , but this will allow only 1 grade to be stored per student (if storing multiple grades is not yet part of your assignment, I'm sure it will follow).

Now you've a structure, you can create a structure variable from it, or why not direct a whole array? (as you want to store multiple students)
You can declare a structure variable of type student like this:

student stud0;

Now, lets do something interesting with it, lets change his name and set some grades:

stud0.name = "John"; // set name
stud0.grades[0] = 5;  // give 'John' five out of whatever you want
stud0.grades[1] = 7;  // set another score

A …

Sky Diploma commented: Have to Admire the effort on explaining the basics :) !!! +6
Yiuca commented: Just had to rep a post like this, looks like plenty of effort went into it. :) +1
tux4life 2,072 Postaholic

@RobBrown:
>was rather unhelpful, and honestly not very bright...

I'm very sorry that my eyes aren't good enough to see the error messages on your computer's monitor.
Do you maybe expect that I'm clairvoyant?

tux4life 2,072 Postaholic

@wildgoose:
stricmp() is a non-standard function and therefore isn't portable as well.
However, everyone can quickly put together his own stricmp() function, or use some kind of workaround to compare strings in a case-insensitive manner.

tux4life 2,072 Postaholic

There are already plenty. :P

Plenty of questions, plenty of weak programmers, or both ?

tux4life 2,072 Postaholic

@tux4lyf:

i am not putting importance on file functions so missed
fp==NULL check and used !feof()
i only wanted to so the encryption/decryption concept.

Only that proves to me that you didn't get what they describe in that link :)
It's not because you quickly want to test out some code that you may use bad coding styles.
Bad coding styles are considered: bad, so you don't have to use them, under any circumstances.
It would also not be a bad idea to format your code when you post/write it.