Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Super simple and informative exmple of using CGO
package main
// #include <ctype.h>
import "C"
import "log"
func main() {
for i := 32; i<126; i=i+1 {
log.Printf( "'%s' (%3d) isalpha: \t%d", string(byte(i)), i, C.isalpha(C.int(i)) )
}
}
Owner
2013/07/08 13:27:55 ' ' ( 32) isalpha:  0
2013/07/08 13:27:55 '!' ( 33) isalpha:  0
2013/07/08 13:27:55 '"' ( 34) isalpha:  0
2013/07/08 13:27:55 '#' ( 35) isalpha:  0
2013/07/08 13:27:55 '$' ( 36) isalpha:  0
2013/07/08 13:27:55 '%' ( 37) isalpha:  0
2013/07/08 13:27:55 '&' ( 38) isalpha:  0
2013/07/08 13:27:55 ''' ( 39) isalpha:  0
2013/07/08 13:27:55 '(' ( 40) isalpha:  0
2013/07/08 13:27:55 ')' ( 41) isalpha:  0
2013/07/08 13:27:55 '*' ( 42) isalpha:  0
2013/07/08 13:27:55 '+' ( 43) isalpha:  0
2013/07/08 13:27:55 ',' ( 44) isalpha:  0
2013/07/08 13:27:55 '-' ( 45) isalpha:  0
2013/07/08 13:27:55 '.' ( 46) isalpha:  0
2013/07/08 13:27:55 '/' ( 47) isalpha:  0
2013/07/08 13:27:55 '0' ( 48) isalpha:  0
2013/07/08 13:27:55 '1' ( 49) isalpha:  0
2013/07/08 13:27:55 '2' ( 50) isalpha:  0
2013/07/08 13:27:55 '3' ( 51) isalpha:  0
2013/07/08 13:27:55 '4' ( 52) isalpha:  0
2013/07/08 13:27:55 '5' ( 53) isalpha:  0
2013/07/08 13:27:55 '6' ( 54) isalpha:  0
2013/07/08 13:27:55 '7' ( 55) isalpha:  0
2013/07/08 13:27:55 '8' ( 56) isalpha:  0
2013/07/08 13:27:55 '9' ( 57) isalpha:  0
2013/07/08 13:27:55 ':' ( 58) isalpha:  0
2013/07/08 13:27:55 ';' ( 59) isalpha:  0
2013/07/08 13:27:55 '<' ( 60) isalpha:  0
2013/07/08 13:27:55 '=' ( 61) isalpha:  0
2013/07/08 13:27:55 '>' ( 62) isalpha:  0
2013/07/08 13:27:55 '?' ( 63) isalpha:  0
2013/07/08 13:27:55 '@' ( 64) isalpha:  0
2013/07/08 13:27:55 'A' ( 65) isalpha:  1
2013/07/08 13:27:55 'B' ( 66) isalpha:  1
2013/07/08 13:27:55 'C' ( 67) isalpha:  1
2013/07/08 13:27:55 'D' ( 68) isalpha:  1
2013/07/08 13:27:55 'E' ( 69) isalpha:  1
2013/07/08 13:27:55 'F' ( 70) isalpha:  1
2013/07/08 13:27:55 'G' ( 71) isalpha:  1
2013/07/08 13:27:55 'H' ( 72) isalpha:  1
2013/07/08 13:27:55 'I' ( 73) isalpha:  1
2013/07/08 13:27:55 'J' ( 74) isalpha:  1
2013/07/08 13:27:55 'K' ( 75) isalpha:  1
2013/07/08 13:27:55 'L' ( 76) isalpha:  1
2013/07/08 13:27:55 'M' ( 77) isalpha:  1
2013/07/08 13:27:55 'N' ( 78) isalpha:  1
2013/07/08 13:27:55 'O' ( 79) isalpha:  1
2013/07/08 13:27:55 'P' ( 80) isalpha:  1
2013/07/08 13:27:55 'Q' ( 81) isalpha:  1
2013/07/08 13:27:55 'R' ( 82) isalpha:  1
2013/07/08 13:27:55 'S' ( 83) isalpha:  1
2013/07/08 13:27:55 'T' ( 84) isalpha:  1
2013/07/08 13:27:55 'U' ( 85) isalpha:  1
2013/07/08 13:27:55 'V' ( 86) isalpha:  1
2013/07/08 13:27:55 'W' ( 87) isalpha:  1
2013/07/08 13:27:55 'X' ( 88) isalpha:  1
2013/07/08 13:27:55 'Y' ( 89) isalpha:  1
2013/07/08 13:27:55 'Z' ( 90) isalpha:  1
2013/07/08 13:27:55 '[' ( 91) isalpha:  0
2013/07/08 13:27:55 '\' ( 92) isalpha:  0
2013/07/08 13:27:55 ']' ( 93) isalpha:  0
2013/07/08 13:27:55 '^' ( 94) isalpha:  0
2013/07/08 13:27:55 '_' ( 95) isalpha:  0
2013/07/08 13:27:55 '`' ( 96) isalpha:  0
2013/07/08 13:27:55 'a' ( 97) isalpha:  1
2013/07/08 13:27:55 'b' ( 98) isalpha:  1
2013/07/08 13:27:55 'c' ( 99) isalpha:  1
2013/07/08 13:27:55 'd' (100) isalpha:  1
2013/07/08 13:27:55 'e' (101) isalpha:  1
2013/07/08 13:27:55 'f' (102) isalpha:  1
2013/07/08 13:27:55 'g' (103) isalpha:  1
2013/07/08 13:27:55 'h' (104) isalpha:  1
2013/07/08 13:27:55 'i' (105) isalpha:  1
2013/07/08 13:27:55 'j' (106) isalpha:  1
2013/07/08 13:27:55 'k' (107) isalpha:  1
2013/07/08 13:27:55 'l' (108) isalpha:  1
2013/07/08 13:27:55 'm' (109) isalpha:  1
2013/07/08 13:27:55 'n' (110) isalpha:  1
2013/07/08 13:27:55 'o' (111) isalpha:  1
2013/07/08 13:27:55 'p' (112) isalpha:  1
2013/07/08 13:27:55 'q' (113) isalpha:  1
2013/07/08 13:27:55 'r' (114) isalpha:  1
2013/07/08 13:27:55 's' (115) isalpha:  1
2013/07/08 13:27:55 't' (116) isalpha:  1
2013/07/08 13:27:55 'u' (117) isalpha:  1
2013/07/08 13:27:55 'v' (118) isalpha:  1
2013/07/08 13:27:55 'w' (119) isalpha:  1
2013/07/08 13:27:55 'x' (120) isalpha:  1
2013/07/08 13:27:55 'y' (121) isalpha:  1
2013/07/08 13:27:55 'z' (122) isalpha:  1
2013/07/08 13:27:55 '{' (123) isalpha:  0
2013/07/08 13:27:55 '|' (124) isalpha:  0
2013/07/08 13:27:55 '}' (125) isalpha:  0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment