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...
Type: Posts; User: Ronerote
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...
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...
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...
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...
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...
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...
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...
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...
OK. Thank you very much for your help and support, laserlight.
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);...
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...
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)...
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...
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...
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...
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.
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...
I understand. Thank you for your help, john.c!
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...