Strchr (): differenze tra le versioni
Vai alla navigazione
Vai alla ricerca
(Creata pagina con "La funzione '''strchr()''', dichiarata nel file header "''/usr/include/string.h''" come segue: char *strchr (char *__s, int __c) cerca la prima occorrenza del valore __c nell...") |
Nessun oggetto della modifica |
||
| Riga 20: | Riga 20: | ||
Dim st As Stream | Dim st As Stream | ||
st = Memory strchr(s, Asc("d")) For Write | st = Memory <FONT color=#B22222>strchr</font>(s, Asc("d")) For Write | ||
Write #st, CByte(Asc("X")) As Byte | Write #st, CByte(Asc("X")) As Byte | ||
st.Close | st.Close | ||
Versione delle 18:38, 30 mar 2018
La funzione strchr(), dichiarata nel file header "/usr/include/string.h" come segue:
char *strchr (char *__s, int __c)
cerca la prima occorrenza del valore __c nella stringa __s.
Volendola utilizzare in Gambas, bisognerà dichiararla con Extern, nonché dichiarare la libreria di C: libc.so.6, nella quale la funzione è contenuta:
Private Extern strchr(__s As String, __c As Integer) As Pointer In "libc:6"
Mostriamo un esempio, nel quale si sostituirà un carattere all'interno di una stringa. Bisognerà utilizzare i " Memory Stream " per scrivere nell'area di memoria puntata dal Puntatore restituito dalla funzione esterna strchr( ):
Library "libc:6"
' char *strchr (char *__s, int __c)
' Find the first occurrence of C in S.
Private Extern strchr(__s As String, __c As Integer) As Pointer
Public Sub Main()
Dim s As String = "abcdefg"
Dim st As Stream
st = Memory strchr(s, Asc("d")) For Write
Write #st, CByte(Asc("X")) As Byte
st.Close
Print s
End