Search:

Type: Posts; User: Ronerote

Search: Search took 0.01 seconds.

  1. Ah, I understand. Except why you check if...

    Ah, I understand. Except why you check if endptr[0] != '\0', is it in case the user passes as an argument a null terminator?

    I have another question: if I checked if every character of every...
  2. You are right, it's only checking the first...

    You are right, it's only checking the first character and this is not what I want. strtol will also return 0 if no conversion could be performed, so I don't need to check if the numbers are valid and...
  3. Okay, now it's working properly. #include...

    Okay, now it's working properly.


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

    int main(int argc, char *argv[]) {
    // We first check whether the user is passing 3 arguments...
  4. Checking if the arguments passed to the main function are numbers is not working

    I'm trying to write a program that needs to be passed 3 numbers as arguments by means of the CLI. This is the code:


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

    int main(int...
  5. Whoops! I didn't notice it. I understand why the...

    Whoops! I didn't notice it. I understand why the result was always 19 hours now. It's because I was subtracting the remainder, so I was getting the quotient. But with difference %= (60*60); I...
  6. Cannot calculate the difference between two dates

    I'm trying to calculate the difference between two dates (the current date and a date stored in a structure) expressed in hours, minutes and seconds, but when I print the results, it's not being...
  7. Does coloring the output reduce portability?

    I would like to know whether coloring the output of a program is a good practice and if it reduces portability. For example, printing an error message in red:

    #include <stdio.h>
    #include...
  8. Replies
    1
    Views
    4,766

    Best practice for true/false variables

    Every time I have a variable of which value will only be either 0 (false) or 1 (true) I use the int type. However, I decided to investigate a bit to see if there are more ways to do it. I would like...
  9. Replies
    6
    Views
    2,085

    OK. Thank you very much for your help and...

    OK. Thank you very much for your help and support, laserlight.
  10. Replies
    6
    Views
    2,085

    Ah, I understand. So if the EnterName() function...

    Ah, I understand. So if the EnterName() function were like this:

    void EnterName(char *name, const size_t NAME_SIZE) {
    printf("Please, enter your name: ");
    fgets(name, NAME_SIZE, stdin);...
  11. Replies
    6
    Views
    2,085

    Okay, so the header file must only have the...

    Okay, so the header file must only have the functions used in the main one even if another functions are used inside it, right?


    Yes. Something wrong happened when I pasted the code here, I'm...
  12. Replies
    6
    Views
    2,085

    When should a function be encapsulated?

    Hi, I'm starting to get used to coding a C program using different source files. I would like to know when should a function be encapsulated (so it can only be used on the *.c file it was defined in)...
  13. I see. I didn't know that. I knew a string is...

    I see. I didn't know that. I knew a string is actually an array, and that an array is a pointer to its first element, that's why I was a bit confused when I discovered you can assign a pointer a...
  14. Yes, my fault. I didn't notice it. strncpy(noun,...

    Yes, my fault. I didn't notice it. strncpy(noun, "point", 6) works as well.


    Does that mean that when I assign a char pointer a string (e.g., char *noun = "point";) the string I typed is actually...
  15. Why can a string be assigned to a 'char' pointer?

    I was making a program that asked the user for a number and printed the number of points the user typed, but changing the grammatical number of the noun. For example: if I type "1", the program...
  16. You are right. Silly me! I don't even know why I...

    You are right. Silly me! I don't even know why I used the root variable, I did it right on the FreeWholeList() function.
    Thank you very much Salem.
  17. "Segmentation fault" when returning the extracted node from a LIFO linked list

    I'm starting to learn to work with linked lists. Specifically, I'm trying to make a LIFO (Last In, First Out) linked list. I made different functions to insert a node, to print the whole list, to...
  18. Replies
    2
    Views
    5,172

    I understand. Thank you for your help, john.c!

    I understand. Thank you for your help, john.c!
  19. Replies
    2
    Views
    5,172

    "Rock, paper, scissors" game won't end

    Hi, I'm making a simple "Rock, paper, scissors" game in C to practice the usage of pointers in functions to modify variables defined in the `main()' function. The problem is that when one of the...
Results 1 to 19 of 19