use strtok function/* Compile options needed: none */ #include <string.h> #include <stdio.h>char *string = "a string,of ,,tokens"; char *token;void main(void) { token = strtok(string," ,"); /*There are two delimiters here*/ while (token != NULL){ printf("The token is: %s\n", token); token = strtok(NULL," ,"); } } The output of this program is as follows: The token is: a The token is: string The token is: of The token is: tokens
thx all,but how can I get the socket.h??? the inet_addr doesn't work when I link it,
ip是可以变得,比如有时候变成192。168。11。111长度也就不同了,立即给分
DWORD ip;
ip=inet_addr("192.168.0.1");
memcpy(val,&ip,4);
error C2664: 'memcpy' : cannot convert parameter 2 from 'unsigned long' to 'const void *'
*/ #include <string.h>
#include <stdio.h>char *string = "a string,of ,,tokens";
char *token;void main(void)
{
token = strtok(string," ,"); /*There are two delimiters here*/
while (token != NULL){
printf("The token is: %s\n", token);
token = strtok(NULL," ,");
}
}
The output of this program is as follows:
The token is: a
The token is: string
The token is: of
The token is: tokens
the inet_addr doesn't work when I link it,