我想加载一个代理列表,用':'分隔符分割每一行,然后将其加载到一个结构中:
struct proxy_data {
ushort type;
char *ip;
uint16_t port;
};
void load_proxies( char * proxy_file )
{
FILE * in;
struct proxy_data * temp = NULL;
if( ( in = fopen( proxy_file, "rt") ) == NULL )
{
fprintf( stderr, "\nCan't open input file!\n");
exit( 0 );
}
while( !feof( in ) )
{
temp = malloc( sizeof( struct proxy_data ) );
fscanf(in, "%s ",temp->type);
fscanf(in, "%s ",temp->ip);
fscanf(in, "%s ",temp->port);
};
fclose( in );
}
但是我在编译时遇到了很多错误。
如何将每一行加载到结构中?