Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There are several ways to write that program. Probably one of the simplest is to use vectors and iterators.

Step 1: Create a vector of ints that will hold all the numbers from 0 to ???

Step 2: create a function that displays all the numbers in the vector. Pass the vector to this function by reference.


Step 3: create a vector<int>::iterator that will be used to iterate through the list

Step 4: in a loop call vector's erase() method to erase the value currently pointed to by the iterator, then increment the iterator, Continue this loop until the vector >= to the vector's end() method. On each iterator of the loop call the function you wrote in step #2 above.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

By password protect I was assuming he meant that when you click on a file a window would popup and ask for a password, something similar to password-protected zip files. So that you could have different passwords for different files.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you use the second option, the one with two stars, then you have to pas a pointer to the pointer ResizeArray( &array, size, DefaultSIZE);

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think you are presenting something a little different than what I had in mind.

The first time around the first number is deleted.
The second time around the second number is deleted.
The third time around the third number is deleted.

That keeps going at the end of the list of numbers, at that time the process starts all over again.

0 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 // first number was deleted
1 3 5 6 7 8 9 // second number from above list was deleted
1 3 6 7 8 9 // third number from above list was deleted
1 3 6 7 9 // fourth number from above list was deleted
// Since there is no 5th number to be deleted we start back at the first number
3 6 7 9 // first number from above list was deleted
3 7 9 // second number from above list was deleted
3 7 // third number from above list was deleted
7 // first number from above list was deleted

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

AFAIK it is not possible to password protect files on either MS-Windows or *nix. So the best solution is gerard's suggestion. Copy the files onto an external drive and delete the originals.

jephthah commented: incorrect. there are several ways. whether it's "worth it" is another question, but one can do it. -1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you want to display something on the same line of the screen as a previous instance, such as time, then just use '\r' to move the cursor back to the beginning of the first line. It does something similary to when you press the Backspace key on the keyboard.

#include <stdio.,h>
#include <windows.h> // assumes MS-Windows operating system
int main()
{
    int counter = 0;
   int i;
   for(i = 0; i < 1000; i++)
  {
      printf("\r%d", counter;
     counter++;
     Sleep(1000); // 1 second pause
  }
  return 0;
}

The above just displays the value of a counter, so you will have to modify the program to display the time (hours:minutes:seconds).

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I would make a second array then copy the elements you want to keep into it. When done delete all the elements of the original array, then copy the contents of the temp array into the original array. Doing that I believe you will only need two simple loops, one to do the first job and another to do the last job.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>void ResizeArray(float *array, int size, int SIZE){

the first parameter has to have two stars, not one. With one star all you have is a local pointer which is a COPY of the original. In c++ you have two choices:
(1) void ResizeArray(float **array, int size, int SIZE){ // pointer to pointer

(2)void ResizeArray(float *& array, int size, int SIZE){ // reference to pointer

If you use the second option then you don't have to change the code in that function If you use the first option then some minor code changes will be necessary.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The link doesn't work.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You will have to make it a DLL then in VB use the same syntax that you would use with any other DLL. For details read these links

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

When find() failes it returns std::string::npos, which is an unsigned integer. So testing with an integer is useless.

size_t pos;
while( (pos = data.find(data1)) != string::npos)
{
     data.replace(pos,data1.length(),data2);
}

The danger with the above is when data1 contains data2. In that case the above would become an infinite loop.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't understand what the problem is. Your program runs ok for me. If you are concerned about it displaying the return value in scientific notation, add << fixed before the call to recursion function.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you are using c++ why use character pointers? Just include <string> and use the std::string class becuse its much easier to use.

All you need to do is define a class or structure with two objects: std::string word and int count.. Then you could create a <vector> of that class/structure

As for the code you posted -- its too unformatted for me to bother reading. The next time you post put the code in [code] [/code] tags.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Do you want static linking or dynamic linking? Such as do you want to link with the *.lib that came with the *.dll (if there was one), or use LoadLibrary() to load the DLL into memory?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

For those of us (like me) who have no clue who St George was, here is a link

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>float array[DefaultSIZE];
That array can not be resized. If you want to resize it then you have to declare it as a pointer and allocate the size. float* array;

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The mod operator works on integers, not letters. Put the letter in single quotes and it will work because that will change the letter to an integer rand() % 'z' But that probably will not be what you are looking for.

read this tutorial

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>A colleague advised me that I should store string pointers for efficiency

There is no efficiency gained by declaring pointers to std::string objects. In fact it will be less efficient because you have to allocate memory before it can be used.

It's somewhat different with C style character arrays. With them you have one of two choices
(1) declare the arrays to be a fixed size, which needs to be large enough to hold the longest string you might want to copy into it. That can waste a lot of memory of there are a lot of strings.
(2) declare a char pointer and allocate memory so that its only large enough to contain a specific string. Example: Note that you still have to duplicate the string. Somewhere in your program, either here or in the read() function new memory has to be allocated for each string read from the file.

struct node
{
    char* data;
    struct node* next;
}

void add(const string& d)
{
    struct node* newnode = new struct node;
    newnode->data = new char[d.length()+1]
    strcpy(newnode->data, d.c_str());
}

The std::string c++ class avoids making you, the programmer, deal with both the above two problems. So if you are using std::string then you don't have to worry about efficiency.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>head->data=&s;

That's the problem. Don't do that in a linked list. Instead, let the linked list own the memory for all strings by removing the pointer

struct sNode
		{
			string  data;
			sNode * next;
		};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

higher value? lower value? higher or lower than what?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>(Also i should send size of it by using strlen, right?

No. Count the length as you enter the characters into the array. The function convert() is already doing that -- variable index. Just pass the value of index instead of strlen().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Now if I input 32432, 23432, 23234, 1233,9898, 87343, 238432

gets() is a horrible function because if the input buffer is not large enough to hold all the characters you type then it will just scribble any excess characters all over memory. So if you typed that all on one line before hitting the <Enter> key then gets() will crash your program. gets() doesn't stop at the first spaces, but only when '\n' is encountered.

A better way to do it is to use fgets(), which will limit the input to the size of the input buffer. The problem with fgets() is that it may put the '\n' in the buffer too, which you will have to remove. fgets(stn, sizeof(stn), stdin); [edit]gerard ^^^ posted the correct example.[/edit]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what's so hard about using the functions in time.h???

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Since you put random integers in that character array strlen() may still not work if there are embedded 0s in that array. The safest way is to pass the length of the array as another parameter.

>> printf("Your encrypted message is: \n %d\t",fmod(b[index],n));

fmod() returns a float, not an integer. use "%f", not "%d"

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

put inFile.ignore() after line 8 to remove the '\n' from the input buffer.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It looks ok to me. Just make sure the calling function deletes the array when done with it to avoid memory leaks.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Please I want a help for I have special Software uses for laser machine
And this software using a dongle and beside a dongle there are another software help the dongle call microdoginstdrv.exe
and my questions now can I make my software work without the dongle because I lost the dongle and the company which produce the dongle is closed what i can do Sir.,

Years and years ago I wrote MS-DOS programs that used those things for security. If you lost yours then just ask the company that wrote the program for another one. But if your version of the program is as old as the ones I wrote you will probably have to buy upgrades, if you can get them at all. Getting a new dongle will do you no good until it is programmed with the keys that the software company used.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You posted the wrong part of the program. The problem is with the two classes you have defined. Just declare the class destructor as virtual and the error will be fixed.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

lines 10 and 14: Attempting to call strlen() with an array of integers instead of a character array. See the parameter to that function. You might want to add another parameter to that function that is the number of entries in the array. void encrypt(int b[50], int size)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You have to pass to script_start a pointer to a pointer (two stars, not one) so that it can change it

int  script_start(lua_State **L)
{
	*L = lua_open();
	if (*L == NULL)
	{
		script_error(L, "%s", lua_tostring(L, -1));
		return -1;
	}

	luaopen_base(*L);
	luaopen_table(*L);
	luaopen_io(*L);
	luaopen_string(*L);
	luaopen_math(*L);
	luaopen_debug(*L);

	return 0;
}

And see the two changes here too

int main(int argc, char *argv[])
{
	lua_State *L = NULL;
	script_start(&L);
	script_end(L); //error here (accces violation)
	return 0;
}

>>script_error(L, "%s", lua_tostring(L, -1));
When *L == NULL how do you possibly expect that line to work??

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Use MS Access to put a password on it. Then you will have to change your program to use that password when opening the database.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

from what I seen in this link that is a file produced by Visual FoxPro. So the easiest way to do what you want is to buy a copy of VFP and let it export the data to a text file.

Also read this link

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You just need to add the commas outFile << s1 << ',' << ss << ',' << p << endl One problem you might encounter is if the text filed contains a comma. In that case you have to enclose it in double quotes.

For example: 1997,Ford,E350,\"Super, luxurious truck\" The backslash \ goes in your c++ program, not in the file itself.

Here is more about those csv files.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The expected responses are stupid. A question is either correct or wrong. The other two are subjective -- computer programs don't know how to think by themselves, at least not yet. They can't distinguish between correct and nearly correct.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Or it might be every American is a gun-tote'n gunslinger.

jephthah commented: i think that's more like some americans' stereotype of themselves. the reality is less cowboy, and more gangbangers and rednecks. +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes I agree code snippets is a joke. Why? Because most of those posted in the past few months are not code snippets at all but just questions in which the op erroneously selected code snippet. Then the mods have to go in and correct those posts.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Get the input as a string then parse it. See Polish Notation

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There are a couple workarounds for that problem. Read this link.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There are a lot of different kinds of databases, from simple text files, binary files, SQL relational databases (such as MySQL). The node structure doesn't lend itself to binary files very well because of that character pointer.

Since the linked list will be relatively short you would probably want to read the entire list into memory when the program starts, then write it back out with all the changes before the program ends.

I would design the text file so that the class name appears between brackets, so that the program can distinguish it from student names, something like this:

[class1]
student1
student2
student3
[class2]
student4
student5

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can view the comments of the rep you have been given by looking in your CONTROL PANEL (see the link at the top of every DaniWeb page)

You could also do it your way, but press your browser's Back button or just clicking anywhere outside the rep box when you are finished reading the comments.

VernonDozier commented: Here's some "rep". It won't count, but thanks. +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

link doesn't work

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You need to declare it like this: char src[100]="eretznehederet"; so that variable src is not a pointer into read-only memory. you can change the 100 to anything you want, as long as its large enough to hold all the text you want to put into it.

Next, at the end of that split function use strcpy() to copy the contents of temp back into src. strcpy(src,temp);

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes you could use a vector of structures. The structure just has two members: string extension and int count.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Oh what sad news. We will surly miss him very much. He was one of the best contributors here at DaniWeb. Thank you for posting to let us know of that very sad event.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm glad you enjoyed your trip :) Next time you visit you might want to go somewhere else, your experience may be much different. For example take a train from San Francisco California to New York, which is a trip of 3,000 miles across very diverse territory. Don't expect to see any Kangaroos though, we don't have any such animals except in zoos.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>then I free (x); and i'm fine? and will not have a memory leak?
Yes, that's the way to do it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what u mean by this: field width specifiers
any example??
thanks in advance

if you want a field to be 5 characters, then printf("%5s", "Hello");. If you want the text to be right justified then its the same with a - symbol printf("%-10s", "Hello"); Write yourself a little program to test that out for yourself so that you can see how it works.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The macro NULL is intended for pointers, not integers, Instead of casting NULL to int why not just pass 0? It would make more sense. Example: line 11 should be like this: if ( numOfArrays == 0 && sizeOfEachArray == 0) Remember: integers are not pointers (normally) so using NULL for them is an inappropriate use of that macro.

>>I can't free stringArray2 from main
why not?

>> makeString ( (int)NULL, (int)NULL );
The string can not be free'ed that way. Make another function to free the array void FreeString(char **string, const int numOfArrays, const int sizeOfEachArray )

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

**sigh**