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

You should create another thread and put that serial port stuff in it so that it doesn't block the gui main thread. Then when something comes in collect the string(s) and send a windows message to the main gui thread so that it can display the string(s) or do something else with them.

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

how did you write the gui? win32 api, MFC, wxWindows or something else? And is the serial port code in the same or different thread than the gui?

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

If the reference (e.g. int*& thingy;) was actually allocated somewhere else then your class destructor should not do anything with it. Let whatever created it destroy it.

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

CreateProcess(). There may be some internal cmd.exe functions that can only be executed with system(), such as "cls", so you may have to experiment with it.

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

hi,
using this methodology, is there a piece of code I could write if after where a folder in directory is detected to scan all files in that folder and then return to the root folder to continue?

Many thanks

Use recursion. There are some examples of that in the code snippets.

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

reading files is the same in console and gui programs. The difference between C and C++ is that C++ will use fstream and C will use FILE*. There are many tutorials and code snippets that will show you how to read a file using FILE*. Here is a google list.

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

I suppose you could have your gui present a list of commands, then when the user selects one just have your program use system(), ShellExecute(), or CreateProcess(), depending on how much control you want to have over it, to execute it,

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

The >> operator stops at the first space, so if you enter "John Doe" as the name the cin will put John in name and Doe in Address. Change the >> operator to getline getline(cin, name);

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

>>int personaladdressbook[50];


Almost struct addressbook personaladdressbook[50];

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

looks staged.

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

Oh well, win some, lose some. Congratulations to Canada for that win. But we still have more medals than they do.

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

You can open any file with FILE*. It doesn't matter what the extension is. FILE* fp = fopen("name.html","r");

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

Of course. Since myfile is ofstream it is not necessary to specify ios::out because that's what ofstream does anyway.

name += ".sta";
myfile.open(name.c_str());
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 59: What will that function do if the parameter Dictionary object gets destroyed?? A: All those pointers will become invalid. It is better if the this object creates its own copy of the Index array so that it will own all the memory instead of relying on the memory allocated by some other dictionary object.

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

1) Change you function name. What the hell is "mv" ? I wouldn't know
just by looking at the name.

You apparently have never used *nix. mv is a common *nix program that moves a file (or directory) from one place to another. Lots of *nix program have very cryptic names and arguments.

>>@vidit_x & @firstPerson & WaltP - .

As for closing files -- it depends. Like return 0; in main() you can elect to close it or not. I only close files if there is no other code to be executed, that is, if the function just returns after the file processing is finished. There are obvious times when the file(s) must be explicitly closed, such as when you want to delete the file. But I don't think that is what firstPerson is talking about. I doubt he meant "never" close files, only don't close them unless its otherwise necessary.

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

I wouldn't make duplicates of A and B, but put the results in matrix C so that A and B are left unchanged.

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

lines 81 and 84. I see no object named "addressbook". There is of course a structure by that name, but no object. Create an object of that type, (don't use the same name as the structure to prevent confusion)

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

>>Can anyone help please? Thx!

Sure can. See below

int main()
{
   // put your code here
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm trying to recall from some work I did 15 years ago. Seem to remember that all you do is xmit a single byte that contains the bit pattern you need. But then again, maybe not. SetCommStat() might do it for you.

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

First you have to create another menu item, and then write a function that implements it. Just a simple linear search will do -- from the first to last items in the array.

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

'\b' (or 8) only does it one time, not 20 times.

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

Are you trying to use a one dimensional array of integers to represent a two dimensional array? If yes, then matrix A would be represented as 1 2 3 4 5 6, and adding matrix B would make it 1 2 3 4 5 6 7 8 9.

To find a value in row n column m in a matrix with X columns and Y rows, the general formula ((n-1) * X) + m [edit]And what ^^^ said too[/edit]

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

Well, I gave you one solution -- a switch with 100 case statements. There is no alternative. But I suspect that kind of problem is not what your instructor has in mind.

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

you could just use '\r' to make the cursor return back to the beginning of the line

int cookTime(int time) {
int second, minute;
    for (minute = time; minute > -1; minute--) {
       for (second = 59; second > -1; second--) {
	sleep(1);
	printf ("\r%2i : %2i", minute, second); 
        }
     }
  }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you can't use > or < in switch cases -- switch can only be used with constants. In the case you posted the if statements are the best way to handle it. I suppose you could write a switch statement with 100 cases, but that would be dumb.

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

How to get all the files in a directory depends on the operating system. In MS-Windows use FindFirstFile() and FindNextFile() found in windows.h. If *nix use OpenDir() and ReadDir(). Then of course you may have to contend with subdirectories. The easiest way to do that is with recursion.

Use strcat() to append text to the user's input variable. Make sure the buffer is large enough to hold all the text.


>>scanf("%s@, directory);
Scanf() is very bad because (1) will not allow spaces in what you type -- many directories in MS-Windows contain spaces, and (2) allows you to enter more characters than the buffer can hold. Replace scanf() with fgets()

>>const char directory[50];
Remove the const keyword because you can't use it in scanf() or fgets(). const means "not changeable".

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

I don't want to continue this discussion here because its hijacking the thread and not relevant to the topic of this thread.

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

>>The language used in the book is so difficult tat i cud'nt understand tat..

Sounds like you are not yet quite read to study pointers. Yes, pointers can get very very messy and complicated very quickly. My suggestion for you is to stick the the simple pointers -- those with only one * -- practice writing programs with them until you understand these one start pointers thoroughly.

You can create pointers with as many stars as possible -- there really is no limit to the number of stars. But practically anything beyond three stars is very rare, and very difficult to comprehend. One and two stars is the most common.

Also remember that most of those ebooks were written by people with Ph.D. and written for college level students (18 years and older).

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

>>Regardless of your excuses; it is bad programming.
Its not an excuse -- its a fact of reality. You can pretty-up the code all you want but when malloc() and realloc() fail the program's gonna crash, and good programming ain't going to help that one bit.

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

>>On realloc failure a new pointer is made pointing to NULL and the original block is lost and not freed.

If realloc() fails, then the program has much larger problems than a little memory leak, such as the entire program will, or is about, to crash due to lack of memory. And that could even extend to the entire operating system. Consequently, on modern computers with several gig ram I don't even worry about realloc() failing. If you are working with embedded systems that have very limited ram then that would be different. But not very many people are doing that.

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

>>Your realloc idiom is one to avoid.
Just standard C. When the first parameter is NULL realloc() acts like malloc().

>>strdup is nonstandard
You might be right. That function can easily be re-implemented for any compiler.

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

The main problem with that class is that the constructor with only one constructor does not initialize the value of both class member variables mdim_ and ndim_.

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

Who the hell wants to read all that crap???

Passwords code snippet here

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

Way too complicated and with unnecessary code. Here is a greatly simplified way to do it. Using strtok() you could parse a string that has more than one kind of deliminator, such as '\n' and '\t' and ',' and the space, these are typical of CVS files (exported XLS files).

int parseStringbyLines(char *buffer, char ***string) 
{
    char** lines = NULL;
    char* ptr;
    char *temp;
    int size = 0;
    if( buffer == NULL || *buffer == '\0' || string == NULL || *string != NULL)
        return 0;
    temp = strdup(buffer); // duplicate the string
    ptr = strtok(temp, "\n");
    while(ptr)
    {
        lines = realloc(lines, (size += 1) * sizeof(char*));
        lines[size-1] = strdup(ptr);
        ptr = strtok(NULL, "\n");
    }
    free(temp);
    *string = lines;
    return size;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you have to change the prototype on line 6.


The & makes the address of the integer, and the * is how to change the value of a pointer integer. If you don't know about pointers yet here is a tutorial by DaWei

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

You sould completly replace cmd.exe with your own version of that program. For example Microsoft has already done it with PowerShell. Another example here

Shinedevil commented: You should totally give me rep, so I can give you rep right back. :P +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you want to display those variables in main() then you will have to declare them in main() and pass them by value to input()

int main()
{
    int temp, windspeed;
    inpuut( &temp, &windspeed);
}

void input(int* temp, int* windspeed)
{
   *temp = 30;
   *windspeed = 20;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>but feel that would cause me to change a lot of code

Oh yea -- one line is a lot of code to change.

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

you might get better shuffling results if you use std::random_shuffle() found in <algorithm>.

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

P.S: How to edit the thread title? Don't know how I typed it wrong :(

You will have to ask a moderator to do it for you, and tell the moderator what you want for the new thread title.

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

you can't realloc() an array what was not a pointer to begin with. you could declare userAnswers as a char***. I've already convered similar situation in another thread here, so I won't repeat it. Just follow the syntax in the other thread how to do it. See my last post in this thread.. It requires three stars because the function needs a pointer to a two-dimensional array.

One difference between that other thread and yours is that your program may need to reallocate the entire array of pointers so that it can hold more strings. That is not very difficult if you keep two counters -- one counter contains the number of char strings that the array can hold (the array's capacity) and another integer that is the number of strings the array currently holds. capacity may be larger than size, but never smaller. When size increases to capacity, then the array needs to be reallocated and capacity increased to the new value.

void UserMode(char ***userAnswers, int* size, int* capacity)
{

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

Q1: use normal FILE* i/o operations. See functions in stdio.h. You should be able to find tutorials.

Q2: see argc and argv arguments to main int main(int argc, char* argv[])

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

>>anyone knows how to use clearscreen with dev system("cls"); If you dont' want to use system() then here is how to do it with win32 api functions.

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

I don't know what the problem is, but I see two glaring problems.

  1. scanf("%s", username); -- what happens if someone enters 20 characters as the user name? A: Program will most likely crash because username can only hold 8 characters. Solution: use fgets() instead of scanf() because fgets() will limit the input to the size of the buffer.
  2. scnaf("%d", &password); -- what happens of someone enters text instead of numeric data? A: the password will not be changed. Solution: Make the password a text array.
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This is one way to do it

void mem_alloc_main(int ind,float ***u_trn)
{
    float** ay;
    ay = (float **)malloc(10 * sizeof(float*));
    for(int i = 0; i < 10; i++)
    {
        ay[i] = (float*)malloc(10*sizeof(float));
        for(int j = 0; j < 10; j++)
            ay[i][j] = (float)rand();
    }
    *u_trn = ay;
}


int main()
{
    srand((unsigned int)time(0));
    float** arry = 0;
    mem_alloc_main(0, &arry);
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j < 10; j++)
        {
            printf("%0.2f ", arry[i][j]);
        }
        printf("\n");
    }

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

You can't insall turbo c on Windows 7.

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

>>turbo c still is not opening with dos
dos just stands for disk operating system. Almost all operating systems have a dos, so which one are you talking about?

Turbo C will not work with MS-Windows 7, so if that is what you are running either forget turbo c or downgrade the os on your computer to win95.

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

If you want mem_alloc_main() to allocate a two-dimensional array of floats, then you have to declare the parameter with three stars, not two. The rule is that mem_alloc_main() needs to have a pointer to a two-dimensional pointer. What you have done is to pass a pointer to a one-dimensional pointer, but allocating it as if it were a two dimensional pointer.

Also: C programs do not require the void* return values to be typecast.

void mem_alloc_main( float ***ptr)
{
    *ptr = calloc((kf_trn+max_del+1),sizeof(float*));
}

int main()
{
   float **arry = 0;
   mem_alloc_main( &arry );
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>This code gives me the following error for the line where the typedef is:

windows.h already defines TRUE and FALSE, which are #define's, not typedefs. I suppose you could undefine them before that typedef, but that could cause many other problems with win32 api functions.

>>or can I only use #if defined(_WIN32) && defined(PERFORMANCE_METING) for that?

Yes. But then you could have tried it yourself to find out.