Search:

Type: Posts; User: rpet

Page 1 of 3 1 2 3

Search: Search took 0.01 seconds.

  1. struct temp_Packet{ int src, dst, typ, prt;...

    struct temp_Packet{
    int src, dst, typ, prt;
    char data[51], buffer[51];
    }temp;
    //end of temp_Packet

    struct SPackets{
    int _src[50], _dst[50], _typ[50], _prt[50];
    char...
  2. Thread: include c++ in c

    by rpet
    Replies
    16
    Views
    4,926

    Quick and dirty: double drand48() //...

    Quick and dirty:



    double drand48() // random number between [0.0, 1.0]
    {
    return rand() / (double)RAND_MAX;
    }

    ...
  3. Replies
    89
    Views
    23,957

    &p.id is a memory address. printf("Id: %d...

    &p.id is a memory address.


    printf("Id: %d \n",&p.id);

    should be:


    printf("Id: %d \n",p.id);
  4. Replies
    89
    Views
    23,957

    if ((data = fopen("data.txt", "rb")) == NULL) {...

    if ((data = fopen("data.txt", "rb")) == NULL)
    {
    printf("Erro ao abrir ficheiro\n");
    }


    If the file could not be opened, you print a message and... continue to read as though nothing had...
  5. Just do it: int howmanyrooms() { int...

    Just do it:



    int howmanyrooms()
    {
    int rooms; /* local variable */

    ...
  6. Replies
    4
    Views
    8,470

    while(!feof(fp)) { fscanf(fp,"%s...

    while(!feof(fp)) {
    fscanf(fp,"%s %s",&e.id,&e.name);
    ...


    The EOF-flag is not set when the last element was read successfully; it is set when the first read operation has failed. That's...
  7. Replies
    7
    Views
    15,923

    In that case, the "null"-string would be what I...

    In that case, the "null"-string would be what I called "some special value that seems appropriate". But keep in mind that the record size must not change. Otherwise your file structure is broken and...
  8. Replies
    7
    Views
    15,923

    There are two ways to do this: 1) Copy the...

    There are two ways to do this:

    1) Copy the file - record by record - and skip the one you want to delete.

    2) "fseek" to the record and mark it as "deleted", i.e. overwrite the name with some...
  9. There are actually two problems here. The first...

    There are actually two problems here. The first one is to find an algorithm that re-orders the array the way you want, and the second one is to translate it into a correct c++ program.

    To...
  10. Replies
    1
    Views
    2,566

    Try to get a more detailed error message using...

    Try to get a more detailed error message using "errno":



    #include <errno.h>
    #include <string.h>

    ...

    if (connect(....) == -1) {
  11. Replies
    51
    Views
    9,595

    That's right. 0.90 using buffered input... ...

    That's right. 0.90 using buffered input...



    #include <stdio.h>

    #define N 0x80000

    unsigned char inputv[N];
  12. Replies
    51
    Views
    9,595

    Elysia, gets() is dangerous and atoi() may fail....

    Elysia, gets() is dangerous and atoi() may fail. You're correct on this. I know that. But this discussion is about to find the fastest solution for a given problem. So let's concentrate on that and...
  13. Replies
    51
    Views
    9,595

    2.14, using an atoi() replacement #include...

    2.14, using an atoi() replacement



    #include <stdio.h>

    int main()
    {
    char b[11];
    unsigned int i, v, n, k, count = 0;
  14. Replies
    51
    Views
    9,595

    Nothing's wrong with gets() in this special case!

    Nothing's wrong with gets() in this special case!
  15. Replies
    51
    Views
    9,595

    scanf() contains some sort of (slow) parser, that...

    scanf() contains some sort of (slow) parser, that we do not need here. Replacing scanf() by gets() and atoi() results in 3.4 (s?) instead of 5.4.



    #include <stdio.h>

    int main()
    {
    char...
  16. Replies
    6
    Views
    1,897

    You cannot assign an array like this. Exception:...

    You cannot assign an array like this. Exception: When the array is defined.


    int i[5] = {1, 2, 3, 4, 5}; /* ok */



    int i[5]; /* definition is here */
    ...
    i = {1, 2, 3, 4, 5}; /* fails,...
  17. Replies
    6
    Views
    19,301

    The second time your program reaches the loop...

    The second time your program reaches the loop header, i is 3, and a[3] is undefined at this point.
    By pure chance a[3] is 0 and the execution stops.
  18. Replies
    3
    Views
    1,715

    Your program does something different. Check the...

    Your program does something different. Check the while / for / fgets part.
  19. Replies
    4
    Views
    4,788

    Due to mode "a+" the new record is always...

    Due to mode "a+" the new record is always appended at the end of the file. Replace 'a+' by 'w+' and your program should work.
  20. Replies
    32
    Views
    4,236

    Sorry, I thought I clarified it already. ...

    Sorry, I thought I clarified it already.

    Adding a variable name to a function prototype is optional. The compiler does not care about it, so we cannot say if it is right or wrong. Each programmer...
  21. Replies
    32
    Views
    4,236

    There is a difference between variable names in...

    There is a difference between variable names in function prototypes and the usage of global variables.
    I said, the variable names are of no use, not that global variables are good.



    This is...
  22. Replies
    32
    Views
    4,236

    Good programming practice is a matter of personal...

    Good programming practice is a matter of personal taste - nothing more. The more people agree with a specific practice the more it is considered "good", no matter if it's really useful or not.
  23. Replies
    32
    Views
    4,236

    Not in my opinion. The "correct" level of...

    Not in my opinion.



    The "correct" level of documentation depends on the programmer, its coding abilities, experience and taste. Example: Hungarian Notation makes the code undoubtedly more...
  24. Replies
    32
    Views
    4,236

    I never use variable names in function...

    I never use variable names in function prototypes.
    They are very helpful in man pages and other documentation, but program != documentation.

    The concept of prototypes was invented to tell the...
  25. Replies
    13
    Views
    11,634

    You should a map work if it cannot compare its...

    You should a map work if it cannot compare its keys?
Results 1 to 25 of 62
Page 1 of 3 1 2 3