Type detection: Difference between revisions

Line 19:
<br><br>
 
=={{header|AWK}}==
<lang AWK>
# syntax: TAWK -f TYPE_DETECTION.AWK
# uses Thompson Automation's TAWK 5.0c
BEGIN {
arr[0] = 0
print(typeof(arr))
print(typeof(0.))
print(typeof(0))
print(typeof(/0/))
print(typeof("0"))
print(typeof(x))
print(typeof(addressof("x")))
print(typeof(fopen("x","r")))
exit(0)
}
</lang>
{{out}}
<pre>
array
float
int
regular_expression
string
uninitialized
address
fileid
</pre>
=={{header|C}}==
The closest C comes to meeting this task, short of building it into the compiler or accessing memory segments via pointers, which is not guaranteed to be portable, is the ctype.h header file. It is part of the C Standard Library and provides 11 methods for detecting the type of a character, out of which the following 7 called in the wrapper function below can be called to be unique. The function accepts a string, but it actually checks the first character. An if ladder is used instead of if-else so that all function calls which return a non-zero value for the character are satisfied and the information is printed.
477

edits