Search:

Type: Posts; User: Meldreth

Page 1 of 6 1 2 3 4

Search: Search took 0.01 seconds.

  1. Replies
    11
    Views
    4,405

    i can't count the times i've tried to come up...

    i can't count the times i've tried to come up with a generic string library for c that's better than doing things manually. more power to you if you can pull it off, but if you're going to write a...
  2. the term "troll" gets thrown around way too much...

    the term "troll" gets thrown around way too much in the newsgroups these days. most recently the definition has changed to

    i don't even bother reading newsgroups anymore unless i want to laugh at...
  3. Replies
    9
    Views
    5,586

    the ?: operator is directly related to if..else...

    the ?: operator is directly related to if..else statements. convert one to the other and you know how it works.


    // ((a>b)?((a>c)?a:c):((b>c)?b:c))
    if (a > b)
    {
    if (a > c)
    a;
    ...
  4. Replies
    12
    Views
    22,567

    that only works if isspace returns 0 or 1, and it...

    that only works if isspace returns 0 or 1, and it doesn't have to because any non-zero value counts as true.
  5. the default access level for classes is private....

    the default access level for classes is private. private members aren't visible in derived classes. change it to this and it should work without making the method completely visible to the outside...
  6. Replies
    5
    Views
    1,672

    fgets preserves any new line character. use puts...

    fgets preserves any new line character. use puts if there's no new line and fputs if there is.


    while(fgets(my, 200, pfile))
    {
    if (!strchr(my, '\n')) puts(my);
    else fputs(my, stdout);...
  7. Replies
    5
    Views
    1,672

    you have to loop if you want all of the lines. ...

    you have to loop if you want all of the lines.


    while(fgets(my, 200, pfile)) puts(my);
  8. Replies
    3
    Views
    20,578

    c doesn't let you concatenate strings with +, you...

    c doesn't let you concatenate strings with +, you need to format the strings together with sprintf or use something like strcat to do the job. i think sprintf is better for this, so here's an...
  9. Replies
    7
    Views
    1,535

    you corrupt the memory with memset. strlen looks...

    you corrupt the memory with memset. strlen looks for a '\0' character but you haven't copied anything into the memory for temp. use the same method for initializing the memory that you did for...
  10. Replies
    9
    Views
    56,628

    that's not right. int is at least 16 bits and...

    that's not right. int is at least 16 bits and long is at least 32 bits. on 32 bit windows both int and long are 32 bits so the guarantee is still there.
    laserlight beat me to it

    if i'm only going...
  11. Replies
    9
    Views
    56,628

    the only assumption i'm making is that there's...

    the only assumption i'm making is that there's always have enough room for the range of values i need. and it's not really an assumption because i guarantee it with my choice of types.

    what you...
  12. Replies
    16
    Views
    2,445

    strcat modifies the first argument and a pointer...

    strcat modifies the first argument and a pointer to a string constant can't be modified. try this instead.


    strcpy(filename, bla);
    strcat(filename, txt);
  13. Replies
    9
    Views
    56,628

    double vs float: double is the default floating...

    double vs float: double is the default floating type. if you say 123.456 it's a double until you cast to float or suffix it with f or F. that's why i prefer double. i haven't been in a situation...
  14. Replies
    6
    Views
    8,242

    you can flush the buffer with a loop. input is...

    you can flush the buffer with a loop. input is line oriented and you can be pretty sure that users have to type enter at the end, so you can just search for that character.


    while (getchar() !=...
  15. Replies
    26
    Views
    9,675

    your code was wrong.

    your code was wrong.
  16. Replies
    26
    Views
    9,675

    then gcc is wrong, or your code is wrong....

    then gcc is wrong, or your code is wrong. laserlight posted a program that uses tentative definitions. do you get the same error with that one?
  17. Thread: About arrays

    by Meldreth
    Replies
    6
    Views
    1,163

    z is just a pointer to some random place in...

    z is just a pointer to some random place in memory. that's wrong because you can't write to memory that isn't yours and memory isn't yours unless you ask for it explicitly. you have to point that...
  18. Replies
    26
    Views
    9,675

    you're compiling as c++. c++ doesn't allow...

    you're compiling as c++. c++ doesn't allow tentative definitions.
  19. Thread: About arrays

    by Meldreth
    Replies
    6
    Views
    1,163

    z is already a pointer. you don't need to use &...

    z is already a pointer. you don't need to use & on it.

    strings can't be copied by assignment. you have to use a loop or strcpy.


    strcpy(names[y], z);
    printf("[%d]=%s\n", y, names[y]);
  20. Replies
    26
    Views
    9,675

    in your example f is a definition but q is a...

    in your example f is a definition but q is a tentative definition. it's only a definition if there isn't another definition for q somewhere else. if there is another definition then q is a...
  21. Replies
    14
    Views
    7,691

    scanf will return 3 if all three numbers are...

    scanf will return 3 if all three numbers are valid. you can do this.


    if (scanf("%f %f %f", &a, &b, &c) != 3)
    {
    fprintf(stderr, "bad input\n");
    exit(EXIT_FAILURE);
    }
  22. Replies
    5
    Views
    2,275

    array indexes start at 0 and end at the size of...

    array indexes start at 0 and end at the size of the array minus 1. your loops should be


    for (a = 0; a < 2; a++)
  23. Replies
    9
    Views
    4,430

    if you're only learning c as a step to c++, c# or...

    if you're only learning c as a step to c++, c# or java, just go ahead and learn the language you want instead of some convoluted learning process. c and c++ are different enough that learning c first...
  24. Replies
    18
    Views
    3,846

    when you use a pointer, are you allocating memory...

    when you use a pointer, are you allocating memory to it or pointing it to an object that already exists? you have to do one of those before you can use the pointer.
  25. Replies
    11
    Views
    34,771

    i meant what i wrote. you broke it. ;)

    i meant what i wrote. you broke it. ;)
Results 1 to 25 of 141
Page 1 of 6 1 2 3 4