In C, NULL is just a synonym for 0. So you really only need to do this...
if (current > n) {
return 0;
}
However, NULL usually refers to a pointer value that is undefined and not an integer. In C, integer values are not references as they are in many interpreted languages. They are scalar and can't be referred to implicitly with a pointer.
If you want to indicate an error condition or undefined behavior when current > n, you will have to provide a separate mechanism for indicating that the value isn't usable. Usually, C functions will return a -1 on an error. Since you are using the integer return for a value, that would mean that a valid value could never be -1.
It looks like you're handling a linked list and you want to limit the number of items to be checked. A possible way around this might be...
int valueOf(t_node *node, int n, int *val){
int current = 0;
int value;
while (node -> next != NULL) {
value = node -> val;
if (current == n) {
// This notation is for dereferencing a pointer.
*val = value;
return 0;
}
if (current > n) {
return -1;
}
node = node -> next;
current += 1;
}
// This method also gives you a way to indicate that
// you came to the end of the list. Your code snippet
// would have returned an undefined value if node->next == null
return -1;
}