字符串1



#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define OPTIONAL  1
#define MANDATORY 2

char* allocate_node(size_t nodes_required, char* node_list, int flag, size_t timeout)
{
	char *cmd[256], *flag_str[10];

	if(flag == OPTIONAL)
		strcpy(flag_str, "optional");
	else if(flag == MANDATORY)
		strcpy(flag_str, "mandatory");

	sprintf(cmd, "allocate N=%d node_list=%s flag=%s timeout=%d",
			nodes_required, node_list, flag_str, timeout);
	return cmd;
}

int main() {
	char * rt = allocate_node(5, "node[001-003],node15", MANDATORY, 10);
	puts(rt);
	puts("********************************");

	char * str_rt = "jobid=116 response_node_list=node12,node13";
	char *node;
	node = strrchr(str_rt, '=');
	puts(node);
	node = node + 1;
	puts(node);
	putchar(*node);
	putchar('\n');
	puts("********************************");
	char str[256] = "";
	strcat(str, "node12");
	strcat(str, ",");
	strcat(str, "node15");
	strcat(str, ",");
	strcat(str, "node18");
	puts(str);
	puts("********************************");
	return EXIT_SUCCESS;
}
相关文章
相关标签/搜索