Search:

Type: Posts; User: Mr_Miguel

Page 1 of 3 1 2 3

Search: Search took 0.01 seconds.

  1. Replies
    3
    Views
    2,869

    Actually, that would be "Vector

    Actually, that would be "Vector<Pair<P, Q> >(length)" instead of "Vector(length)", apparently, since "Vector(length)" gives me a compilation error.

    Either way, thank you. But I'm curious: is there...
  2. Replies
    3
    Views
    2,869

    Creating custom class for vector of pairs

    I have the following code:



    #include <iostream>
    #include <utility>
    using namespace std;

    template<typename T>
    class Vector {
  3. Thread: 3 x 3 loop

    by Mr_Miguel
    Replies
    1
    Views
    993

    The biggest concern here seems to be writing a...

    The biggest concern here seems to be writing a single loop to produce the sequence: 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5 (i.e. how to "leap" from 5 to 0). Seems to me that you'll want to use the modulo...
  4. Replies
    18
    Views
    2,444

    fgets() is preferrable over gets(): ...

    fgets() is preferrable over gets():



    fgets(fileName, 256, stdin);


    Of course, you may encounter the problem that fgets() leaves a newline character ('\n') on your string. strchr() can help...
  5. Replies
    18
    Views
    2,444

    Strings cannot be compared with the operator ==....

    Strings cannot be compared with the operator ==. Use:



    if (strcmp(fileName, "banana.dat") == 0)

    Instead.

    Oh, and don't use gets()
  6. Replies
    7
    Views
    9,092

    You mean like this? #include ...

    You mean like this?



    #include <stdio.h>
    #include <stdlib.h>

    int main() {
    char input [512];
    unsigned int x = 0;
  7. Replies
    7
    Views
    9,092

    Yeah, I assumed scanf() would fail once it...

    Yeah, I assumed scanf() would fail once it encountered a minus sign. It seems not to be the case. I solved the problem using the following code:

    Assuming the user won't enter more than 512...
  8. Replies
    7
    Views
    9,092

    Validating unsigned integers with scanf()

    #include <stdio.h>

    int main() {
    unsigned int x = 0;
    int scanf_value = scanf("%u", &x);
    if (scanf_value != 1) {
    printf("The user has not entered a valid unsigned integer\n");
    }
    else {...
  9. Thank you both for your help. I have successfully...

    Thank you both for your help. I have successfully coded an algorithm to construct those binary trees.

    The output for the second one (in-order: 7 8 11 3 5 16 12 18, post-order: 8 3 11 7 16 18 12 5)...
  10. Constructing a binary tree from its in-order and post-order traversals

    Hi everyone. I'm not gonna lie to you - this is part of an assignment. However, I didn't come here to ask for code.



    Right, my only question right now is how can I construct a binary tree from...
  11. Replies
    7
    Views
    1,596

    Yes, negative numbers are also evaluated as...

    Yes, negative numbers are also evaluated as "true".
  12. Replies
    7
    Views
    1,596

    The answer is 4 because, in C, every value...

    The answer is 4 because, in C, every value different than 0 is "true". In your example, x is, indeed, different than 0, so the answer is 4. If it were zero, the answer would be 5.
  13. Thread: rand()

    by Mr_Miguel
    Replies
    8
    Views
    9,262

    When you call srand() with the same value, the...

    When you call srand() with the same value, the first call to rand() will always return the same number. That's basically what you're doing.
  14. Replies
    6
    Views
    1,945

    Perhaps you mean "buf[0] set to 0"; talking about...

    Perhaps you mean "buf[0] set to 0"; talking about NULL doesn't make much sense there, since "buf[0]" is of type "char".

    So your idea is that fgets() should set "buf" to an empty string, am I...
  15. Replies
    6
    Views
    1,945

    Because "buf" is converted to a char* when passed...

    Because "buf" is converted to a char* when passed to fgets(). For a function to be able to set it to NULL, a char** would be required. Try this yourself. Write a function that receives a char* as a...
  16. Replies
    1
    Views
    1,488

    Do this on a command prompt: your_program >...

    Do this on a command prompt:

    your_program > output.txt
  17. I see... One question, though: what if the user...

    I see... One question, though: what if the user entered LONG_MAX or LONG_MIN as a value, after errno has been set to ERANGE by a previous iteration? Should we "sacrifice" those two values in order to...
  18. http://www.hmug.org/man/3/strtol.php The...

    http://www.hmug.org/man/3/strtol.php



    The strtol(), strtoll(), strtoimax() and strtoq() functions return the
    result of the conversion, unless the value would underflow or overflow.
    ...
  19. Replies
    3
    Views
    3,726

    Oh, but of course! Having an unsigned char*...

    Oh, but of course! Having an unsigned char* instead of a char* did the trick. So, basically, it was converting a signed type to an unsigned type, which gave me unexpected results.

    Thanks for the...
  20. Replies
    3
    Views
    3,726

    Printing a float's bytes...

    #include <stdio.h>

    int main() {
    float f = -118.625f;
    char* c = (char*)&f;
    unsigned int i = 0;
    for (i = 0; i < sizeof(float); ++i) {
    printf("%u\n", c[i]);
    }
    getchar();
  21. Replies
    3
    Views
    5,838

    Now that I'm answering back, I don't think I'll...

    Now that I'm answering back, I don't think I'll need a "mutex-like" named semaphore, anymore, but tell me this: how would I solve this problem?




    //Process A
    //Waits for messages on a shared...
  22. Replies
    3
    Views
    5,838

    Is sem_getvalue() dangerous?

    I seem to recall a teacher saying that sem_getvalue() could be dangerous. Is this true? If so, why? In what circumstances?

    I'm asking you this question because I'm currently doing an assignment...
  23. Replies
    10
    Views
    2,662

    If I'm not mistaken, some operating systems also...

    If I'm not mistaken, some operating systems also leave a '\r' before the '\n'. I think those scanf calls should be converted to fgets + sscanf.
  24. Replies
    4
    Views
    996

    Question about free()

    When I look at free()'s manpage, it mentions that its behaviour is undefined if I pass it a pointer which hasn't been returned by malloc(), calloc() or realloc(), or if the pointer I pass to it had...
  25. Replies
    10
    Views
    27,148

    Excuse me, but I believe the correct conversion...

    Excuse me, but I believe the correct conversion string for a double is "&#37;lf", and not "%f".

    Source: http://linux.die.net/man/3/scanf

    Edit: never mind. printf's conversion strings seem to behave...
Results 1 to 25 of 64
Page 1 of 3 1 2 3