to input data to a function
her i am inputting the data through 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 so开发者_如何学JAVAurce 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);
i want to write a function which inputs the above parameter how to write it ? here i am inputting it the data to place i want to store it. like delete_node.ip.ip_src and so on, where delete_node is a structure. how to write a function which performs the same task that of the above printf statements
Have the function receive a pointer to the struct and use it inside:
int fx(struct WHATEVER *node) {
printf("...");
scanf("%s", buff); /* validate! */
inet_aton(buff, &(node->ip.ip_src));
/* ... */
return 0; /* all ok */
}
精彩评论