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

Don't understand the problem. Do you just want to copy some bytes from the data file to a bin file? The terms "data file" and "bin file" are rather ambibuous, they are both really the same thing.

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

This is one way to do it.

fgets(line,sizeof(line),fp);
// get first token on the line
char* token = strtok(line," ");
if( strcmp(token,"Client:") == 0)
{
   // process line as client
   // call strtok() in a loop to extract the other tokens

}
else
{
    // process line as item
   // call strtok() in a loop to extract the other tokens
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Isn't that how it's supposed to work? When scrolling through a thread only the <DANIWEB> link and search bar are fixed. The other lines are also fixed when scrolling through menus.

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

Line 23: what exactly does sizeof(buf) return? Answer: check line 10 and you will see buf is declared as 1024 pointers, so sizeof(buf) is 1024 * sizeof(char*). Assuming sizeof(char*) == 4 (which it does on MS-Windows and *nix) sizeof(buf) = 1024 * 4 = 4096.

From briefly reading some of the program I suspect line 10 is incorrect, the asterisk shouldn't be there: char buf[1024];

line 9: field_names is also a problem, you use it starting on line 31 but you have never allocated memory for any of those pointers. At that point field_names is nothing more than an unallocated pointer.

line 9 should be like this: char *field_names[15];

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

look in your compiler's limits.h header file. You will find them all there.

and anything bigger than that?

That doesn't make any sense. What do you mean by "bigger than that"?

And also how to calculate this?

How to calculate what? sizeof(object) returns the number of bytes required to store the object, for example sizeof(char) is always 1, sizeof(int) can be 2, 4, or 8 (maybe larger), depending on the compiler and platform. sizeof does NOT return the largest number that can be stored in the int, just the number of bytes an int (or other object) occupies in memory.

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

Read a line. If it starts with Client then you know you have to allocate a new client node. If it starts with Item then add a new Item node to the most recent Client node.

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

There are many ways to accomplish it. You could add a small item at the beginning of each line that identifies it as either client or item.

 fprintf(f,"Client: %s %s\n",head->client_name,head->client_last_name);

 fprintf(f,"Item:  %s %s %f %s %f ",CurrentItem->item_name,CurrentItem->item_state,CurrentItem->item_price,CurrentItem->item_status,CurrentItem->item_price_if_not);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It doesn't work because it never saves the data to the file.

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

but now when i generate a password it has weird characters in it

Because there are unused bytes in the array that contain random junk characters. Initialize the whole array with 0s before doing anything.

char password[5 + 5 + 5 + 5 + 1] = {0}; // 4 Upper, 4 Lower, 2 Num, 2 Symbols

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

How many years did you say you have to write/test that program??

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

are you linking with both libraries?

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

apart from seeing technical words I do not understand,

What didn't you understand?

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

Do you mean the sum of each column? You will need two loops to do that, the outer loops counts N columns and the inner loop counts M rows. It's almost identical to the way you would do it on paper or in an Excel spreadsheet.

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

Oh, normally something that contains the dot is a file extension, such as .txt, .dat, .mex, etc. I thought you were walking about a file format. I never studied MATLAB so I can't help you.

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

That doesn't explain what a .mex file is.

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

Can anyone help me converting it to a .mex file ?

What is a .mex file???

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

line 15 of the code you posted is wring.

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

Other than poor formating, I don't see anything wrong with how you allocated the array. The values in the array are something else.

void John_is_3D(int dimx, int dimy, int dimz)
{

    int ***John; // pointer to pointer to pointer
    John = new int**[dimx]; // array of pointers to pointers


    for (int x = 0; x<dimx; x++)
    {
        John[x] = new int*[dimy];
        for (int y = 0; y<dimy; dimz++)
        {
            John[x][y] = new int[dimz];
            for (int z = 0; z<dimz; z++)
            {
                John[x][y][z] = x*y*z;
                cout << John[x][y][z];

            }

        }
        cout << endl;
    }



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

line 18: since the node is now deleted you might as well stop looking, unless there could be more nodes with the same name.

lines 20 and 21 won't work because current has already been deleted on line 18.

current = prev->next;

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

a+b adds the two ascii values. Look at any ascii table and you will see that 'a' == 97 and 'b' == 98, so a+b = 97+98 = 195. Now look again at that ascii table and find the character whose ascii value is 195.

What you want to do is to save them in an array of characters

char array[3]; // room for 2 characters
array[0] = 'a';
array[1] = 'b';
array[2] = '\0'; // string null-terminator

cout << array << '\n';

[edit] What ^^^ he said too :)

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

It's pretty simple, exactly like deleting the client node from the linked list. The item list is just like the client list.

If current is the node to delete, then

set prev-next = current->next
delete current

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

Here's one way to do it.

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

Have you read this article?

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

line 5 is wrong -- notename[x] is a single character and c_str() returns a string. Maybe line 1 is incorrect -- string notename[10]; which would mean notename is an array of string objects.

string notename = "filename.txt";
x = 1;

cout << notename << endl;
if(remove(notename.c_str()) != 0)
{
perror( "Error deleting file" );
}
else
{
cout << "File successfully deleted";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

duskoKoscica: why are you making this soooo difficult for yourself???

  1. include stdlib.h header file

  2. redirect the output the string you put in the system call to a file.

    "ls -ltr | grep ^- | tail -1 | awk '{ print $(NF) }' >tempfile.txt"

  3. Read the file created by #2 above.

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

create another class for those two then you can make an array of that class. See the examples posted in your other thread.

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

If you have not yet studied structures then declare two arrays, one for 10 student names and the other for the sections. This assumes the names book1, book2, etc never change, so there's no point in storing those strings. If, however, those names can be different for each student then this array won't work because it can't store the names.

char student_sections[10][5][1];
char student_names[10][20];

A more robust solution would be to use a structure and make an array of structures.

struct course
{
   char name[8];
   char section;
};

struct student
{
   char name[20];
   struct course courses[5];
}

struct student students[10];
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You shouldn't have to allocate any new memory -- it's alredy there, just overwrite the fields of the pointer that FindToAdd() returns. I'd also change the name of that function to just Find() so that it better describes its purpose. Once found, just copy the new information into the client structure.

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

That looks right, if the intent is to delete the entire client list.

To do edits you don't need to delete anything. Just search for the client you want then change the value of the client's properties. Of course you will have to get the new values from somewhere, most likely just prompt for them and get keyboard input, very much like when the program got the original client values.

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

To delete the inner list just iterate through the list and delete each node one at a time, something like this: It assumes head->item_data pointer is NOT NULL, so you should probably test for that before executing any of the code in this function.

void DeleItemList(struct client* head)
{
   struct item* save;
   struct item* it = head->item_data;
   while(it->next)
   {
      save = it;
      it = it->next;
      free(save);
   }
   head->item_data = NULL;
 }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what exactly is your question(s) about how to write that program. You will need to use functions srand() and rand() which generates the random numbers, then save the values in an array. Each time a new random number is generated search the array to see if it's already there. If not, then add the number and repeat the process.

There are may ways to sort arrays. Probably the simplest to code is called the Bubble Sort. google for sorting algorithms and you will easily find them.

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

Here is how to create a process remotely on MS-Windows. I don't know about *nix.

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

What event is supposed to cause the program to run? If the program only needs to run once or twice a day then use the operating system to schedule it as G_Waddell suggested 2 days ago.

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

It's just an ordinary text file. I assume you already know how to read text files. You will know the format of the file because you will have to tell the sql server how to export the data. And how to export the data will depend on the sql server you are using.

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

you can't just read from it like an ordinary text file, because it isn't. The smallest SQL compliant database I know of is Sqlite (click here and here )

Even if you go with MS Access you still will have to install the Access Runtime software on the target computer. There's nothing extra to install with Sqlite.

Another option may be to export the sql database into flat files that your program can read

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

The file will do no good without the server. The target computer must have the server software or the server must be on a computer that the target computer can access, such as both computers on the same network.

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

Function AddClient() doesn't return anything. Either make it return something or make it a void function. Try this, where I've remove redundent code.

Try this version, where I removed redundent code.

void AddItemToClient(struct client *head, char item_name[30], char item_state[30], double price, char status[30], double price_if_not, int day, int month, int year)
{
    struct item* it = malloc(sizeof(struct item));
    strcpy(it->item_name, item_name);
    strcpy(it->item_state, item_state);
    strcpy(it->item_status, status);
    it->item_price = price;
    it->item_price_if_not = price_if_not;
    it->issue_date = malloc(sizeof(struct date));
    it->issue_date->day = day;
    it->issue_date->month = month;
    it->issue_date->year = year;
    it->next = NULL;
    it->issue_date->next = NULL;

    if (head->item_data == NULL)
    {
        head->item_data = it;
    }
    else
    {
        struct item* node = head->item_data;
        while (node->next) node = node->next;

        node->next = it;
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

"vous" and "tu"

Never heard of either -- are those English words??

"while / whilst"

I don't recall ever using or hearing the word whilst. And "whom" is rarly, if ever, used today.

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

Will the while loop get confused by multiple NULL characters

No, it will stop when it encounters the first NULL character, all others are ignored.

will fscanf be able to overwrite the NULL character each time

Maybe, it will try to store as many characters as it can in the buffer until it either encounters '\n' in the file, end-of-file, or fills up the buffer.

Why do you want the sum of all characters in the file? That may not work if the sum exceeds the max value that can be stored in num (see the max value in limits.h standard header file).

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

"The vast majority" is another such phrase I dislike, although its more common today than it was 20 years ago.

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

You might like this from Victor Borge's standup skit about phonitic pronunciation.

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

Is there any reason I should rename it to eulerTwo?

You can, but it's not necessary. There is nothing wrong with using numbers in function names -- it's actually pretty commen.

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

Some implementations can grow the stack to use all available memory, same as the heap

But it is still limited -- there is no such thing as an infinite amount of memory or stack space. So Mike's statement is still correct. But --- any program that attempts to use that much memory and/or stack space needs to be redesigned.

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

@Gensk: You didn't say what operating system you are uing. The sugestion by deceptkion works only on MS-Windows. If you are using *nix then you will have to do something else.

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

You can call the basic linux command from within c or c++. For example you could use pipe() to run the ls -rt command and instead of displaying the results on the console screen it will send the results to your program so that you can process them however you wish. You may have to save the results in an array then sort the array by last modified time.

AFAIK there are no other ways to accomplish what you want without resorting to one of the suggestions already posted in this thread. That is, unless you want to write your own operating system in which case you can do whatever you want.

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

IBM -- It's Better Manually

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

I also had failed submit issue the other day -- I pressed Submit and nothing happened, so I pressed it a couple more times. I left the thread for a few minutes to do something else, when I came back to the thread I saw three or four duplicate posts, so I just asked mods to delete the duplicates. I think that was the first time I saw that problem.

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

You can just remove initArray() because it's not necessary to initialize the string before calling fgets(). And there's a much easier and quicker way to do it too -- memset(word1,0,sizeof(word1));

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

The only thing I see wrong with line 19 is **file** insted of just file.

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

I thought normal behavior was to hit Refresh after Submit. I seem to recall this behavior has been discussed before.