User Profile

Collapse

Profile Sidebar

Collapse
kiseitai2
kiseitai2
Last Activity: Oct 19 '18, 08:39 PM
Joined: Jul 27 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Where is the error? Is it at compile time, linking time, or runtime? Please, post the error output!
    See more | Go to post

    Leave a comment:


  • kiseitai2
    replied to Need help converting some c++ to c
    in C
    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...
    See more | Go to post

    Leave a comment:


  • kiseitai2
    replied to using pthread_exit
    in C
    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.
    See more | Go to post

    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...
    See more | Go to post

    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...
    ...
    See more | Go to post

    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]);
    The problem is probably when the 5th thread is created. It is possible that...
    See more | Go to post

    Leave a comment:


  • kiseitai2
    replied to Covert int array to char array in C.
    in C
    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.
    See more | Go to post

    Leave a comment:


  • kiseitai2
    replied to Why is the size of empty constant 1 byte ?
    in C
    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...
    See more | Go to post

    Leave a comment:


  • kiseitai2
    replied to Why is the size of empty constant 1 byte ?
    in C
    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...
    See more | Go to post

    Leave a comment:


  • kiseitai2
    replied to Why is the size of empty constant 1 byte ?
    in C
    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");
    ...
    See more | Go to post

    Leave a comment:


  • kiseitai2
    replied to Why is the size of empty constant 1 byte ?
    in C
    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...
    See more | Go to post

    Leave a comment:


  • Could you post some code samples of what you have tried?
    See more | Go to post

    Leave a comment:


  • kiseitai2
    replied to Need help with Grade calculator code.
    in C
    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...
    See more | Go to post

    Leave a comment:


  • kiseitai2
    replied to Need help with Grade calculator code.
    in C
    You are welcomed! Come back if you get stuck again!
    See more | Go to post

    Leave a comment:


  • kiseitai2
    replied to Need help with Grade calculator code.
    in C
    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!
    See more | Go to post

    Leave a comment:


  • kiseitai2
    replied to Need help with Grade calculator code.
    in C
    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...
    See more | Go to post
    Last edited by kiseitai2; Jun 18 '15, 03:32 PM. Reason: Forgot one set of code tags! :(

    Leave a comment:


  • kiseitai2
    replied to Need help with Grade calculator code.
    in C
    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...
    See more | Go to post

    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.
    See more | Go to post

    Leave a comment:


  • kiseitai2
    replied to Read from file to linked list c++
    in C
    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...
    See more | Go to post

    Leave a comment:


  • kiseitai2
    replied to Read from file to linked list c++
    in C
    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....
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...