我正在尝试使用 g_io_channel_read_chars 方法从 TCP 套接字读取数据并将其转换为长整数。我尝试使用 strtol、atoi,不将 ScanLine 转换为 gchar 指针,使用 ScanLine[0] 访问 ScanLine 的第一个变量,以不同的方式声明 FilterAmount,尽管如此,我的应用程序仍然在该行崩溃。有任何想法吗?
static gchar ScanLine[9640];
long int FilterAmount;
g_io_channel_read_chars (source, (gchar *) ScanLine,1,&BytesRead,&GlibError);
if (BytesRead != 1){
return TRUE;
}
printf("This is my string: %s\n", ScanLine);
FilterAmount = strtol(ScanLine, NULL, 10);
printf 语句的输出为“2”