User Profile
Collapse
-
Where is the error? Is it at compile time, linking time, or runtime? Please, post the error output! -
Read this link and build a function in C that implements the functionality described in the page. Do the same for any other c++ std methods. Remember that c is much simpler than c++ so all you need to do in general is to convert class-like structures into c structures and corresponding functions. Basically, sit down and start reading the c++ standard documentation. If you can't find the equivalent function in the C standard, you will have to understand...Leave a comment:
-
As of late, I am noticing a pattern. Review my responses in previous threads and review (read about) the function of main() in a program.Leave a comment:
-
To allow other threads to continue execution, the main thread should
terminate by calling pthread_exit() rather than exit(3).
http://man7.org/linux/man-pages/man3...ad_exit.3.html
Based on various documentations and some stackoverflow comments, it seems that pthread_exit terminates main() but does not allow the process to terminate. This way, the other threads are allowed to finish execution without resources becoming...Leave a comment:
-
The loop runs 5 times. For loops don't increment until after the execution of the body. As far as I know, 0,1,2,3,4 = 5 runs (I could be wrong for I am not a math major). I have worked with parallel programming and I am 90% sure main quits and deletes s before the 5th iteration can use it. I explained it in my previous reply. Please, read it carefully.
Original code:
Code:for(i=[B]0[/B];i<max;i++) <-I think I see a 0, maybe I am blind...
Leave a comment:
-
All of the responses are wrong! The original code is correct for a program that runs in a single thread. I suspect the problem lies in lack of synchronization between the main thread and the threads you created. The following line is called 5 times (0, 1, 2, 3, 4):
Code://printf("%d",s[i].a); rc=pthread_create(&th[i],NULL,print,(void *)&s[i]);
Leave a comment:
-
Also, remember that a char is a special integer in that it is 8 bits in size. Thus, if you go beyond 255, you will see integer overflows, which means your char element will be wrapped around. Example, 256 -> 0 in unsigned char because the 256 is beyond the size. In binary, 1111 1111 (255) + 0000 0001(1) = 1 0000 0000(0 w/ carry 1 or carry flag on). Just keep that in mind so you don't freak out by the results of your computation.Leave a comment:
-
Don't get me wrong. I understand arrays. I simply reproduced the sample posted by the opener with some modifications to confirm this behavior and yes gcc accepts the syntax without giving an error. It throws a mild warning (warning: initialization makes integer from pointer without a cast [enabled by default]). I figured out what gcc is doing behind the scenes. It takes the address of the array and recast it as a char which means it throws away 3...Leave a comment:
-
I would agree that line 3 should provoke a compiler error, but gcc allows this syntax (char c = "";). However, the content of ch is not the first character in the array, which is the least behavior I would expect. ch always yields 36 in the test program I made. Why does gcc allows a blatantly wrong syntax and doesn't do anything related to what the syntax is trying to convey? It baffles me...Leave a comment:
-
I ran the following program.
Code:int main() { char ch="sad\0"; char ar[10] = "sad\0"; char* x = malloc(10); printf("%d",sizeof(ch));//Outputs actual size of ch printf("%s", "\n"); printf("%d %x", ch, &ch);//Outputs integer representation of ch's contents, hexadecimal value of address of ch printf("%s", "\n");
Leave a comment:
-
Maybe the compiler allocates a char array of about a byte and set the address of ch to array[0], which is the first character in the array? Does sizeof(ch) gives you 1? Does sizeof("") gives you 1 or 4? I am actually intrigued why the compiler wouldn't issue, at least, a warning about using a string literal (which is an array) in a char. I am not savvy on the details of the C and C++ language specifications so I do not know if the compilers...Leave a comment:
-
-
Normally, I would solve the new problem by creating and/or using a data structure. However, from what I gather from earlier posts is that this approach would be beyond the scope of the tools you have at your reach. My original responses were geared towards building the average calculator for a single student. Now, for multiple students you can either run the program every time you need to compute the average grade or you could use a while loop to...Leave a comment:
-
-
P.S. A loop is like having a parrot, it won't stop repeating the same thing until it dies or you tell it to shut up! :P
I hope it helps!Leave a comment:
-
Ok, I have an idea of what tools you have to solve the problem. Your instructor most likely wanted you to use a loop to solve this problem. Why? A loop will allow you to repeat a set of instructions (example, cout << "What color is the next circle?: ";) a set number of times or even indefinitely. For this, I will briefly explain what a couple of loops do, so you can make a decision on which to use!
The while loop will execute...Leave a comment:
-
As per forum rules I can't give you a coded solution, but I will attempt to help you see one possible solution. First, how much of C++ have you learned? Have you tried asking the user how many grades s/he wishes to input? If you ask the user for the number of input events prior to computing the average you will have a value for TotalGrades. Furthermore, you can use the value to know how many times you have to ask the user for grades. This brings...Leave a comment:
-
You forgot to use FunctionElement :: in the method signatures for setElements(... ) and getList(). As a result, the compiler thinks they are global functions instead of methods from the class FunctionElement , so the instructions inside them have no knowledge of the contents inside the class.Leave a comment:
-
Oops, I assumed this person understood how the shift operator worked but was trying to find out why nothing was getting outputted. I also assumed we are looking at the code for two different programs tagged in a single set of code tags. Hence, why we see two different MyStruct definitions (with the second one being the actual linked list node structure) and two main functions. Now that s/he knows about file access permissions, I recommend following...Leave a comment:
-
First, I see you need to close the output file (f.close()) in the first part. However, because the program calls the destructor at the end of its execution, it shouldn't be a problem in this program. The issue is permissions. You are trying to write to a directory in which the program does not have write permission. If you try "Wext1.txt" instead of "C:\\Wext1.txt, " you will see your file near the executable with all the data....Leave a comment:
No activity results to display
Show More
Leave a comment: