2011-04-28 47 views
0

她我是通过printf的将数据输入到一个功能

printf("enter the src ipaddress \n"); 
scanf("%s",buff); 
inet_aton(buff, &(delete_node.ip.ip_src)); 

printf("enter the dst ip address\n"); 
scanf("%s",buff); 
inet_aton(buff, &(delete_node.ip.ip_dst)); 

printf("enter the source port\n"); 
scanf("%d",port); 
delete_node.protocol.proto.uh_sport = ntohs(port); 

printf("enter the destination port\n"); 
scanf("%d",port); 
delete_node.protocol.proto.uh_dport = ntohs(port); 

我想写它输入上述参数如何写一个函数输入的数据?在这里我输入数据来放置我想要存储的数据。如delete_node.ip.ip_src等,其中delete_node是一个结构。如何编写执行相同任务的功能,上面的printf语句

回答

1

的具备的功能收到的指针结构和内部使用它:

int fx(struct WHATEVER *node) { 
    printf("..."); 
    scanf("%s", buff); /* validate! */ 
    inet_aton(buff, &(node->ip.ip_src)); 
    /* ... */ 
    return 0; /* all ok */ 
} 
相关问题