本文整理汇总了C++中split_str函数的典型用法代码示例。如果您正苦于以下问题:C++ split_str函数的具体用法?C++ split_str怎么用?C++ split_str使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了split_str函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: display_func
void* display_func(void) {
int i, j, error;
char message_buffer[LENGHT_MESSAGE], message_buffer_2[LENGHT_MESSAGE];
char filename[LENGHT_MESSAGE];
char confirm_file[LENGHT_MESSAGE];
FILE *fp;
while (state == 0) {
if (recieve_data(LENGHT_MESSAGE, message_buffer) == 0)
draw_new(global_display, "system>> recieve error");
//draw_new(global_display, message_buffer);
if (message_buffer[0] == '0') {
split_str(1, strlen(message_buffer), message_buffer, message_buffer_2);
draw_new(global_display, message_buffer_2);
}
else if (message_buffer[0] == '1') {
//do nothing
}
else if (message_buffer[0] == '2') {
split_str(27, strlen(message_buffer) - 2, message_buffer, message_buffer_2);
strcpy(username, message_buffer_2);
split_str(1, strlen(message_buffer), message_buffer, message_buffer_2);
draw_new(global_display, message_buffer_2);
}
else if (message_buffer[0] == '3') {
split_str(1, strlen(message_buffer), message_buffer, message_buffer_2);
draw_new(global_display, message_buffer_2);
split_str(31, strlen(message_buffer) - 1, message_buffer, filename);
sprintf(message_buffer_2, "downloaded/%s", filename);
fp = fopen(message_buffer_2, "w+");
error = 1;
do {
recieve_file(message_buffer);
fprintf(fp, "%c", message_buffer[1]);
}while(message_buffer[0] != '5');
fclose(fp);
draw_new(global_display, "system>> Downloaded file success.");
}
//Reset value in message_buffer for check while loop's condition
strcpy(message_buffer, "");
strcpy(message_buffer_2, "");
}
return 0;
}
示例2: load_program
void load_program(std::string path){
get_pause();
while(node_view.size() > 0){
delete_node(node_view.begin()->second);
}
clear_local();
std::ifstream cin(path, std::ios::in);
char buffer[100];
std::string str;
int state = 0;
std::getline(cin,str);
int n_nodes = lexical_cast<int,std::string>(str);
std::cout << "N Nodes:" << n_nodes << "\n";
std::vector<Node *> nodes;
for(int i = 0; i < n_nodes;i++){
std::getline(cin,str);
std::vector<std::string> args = split_str(str);
float y = lexical_cast<float,std::string>(args[args.size()-1]);
args.pop_back();
float x = lexical_cast<float,std::string>(args[args.size()-1]);
args.pop_back();
std::string full_name;
for(int i = 0; i < args.size();i++){
full_name += args[i];
if(i != args.size()-1){
full_name += " ";
}
}
std::cout << full_name << "\n";
nodes.push_back(create_and_insert_node(full_name,Vec2f(x,y)));
}
std::getline(cin,str);
int n_connections = lexical_cast<int,std::string>(str);
for(int i = 0; i < n_connections;i++){
std::getline(cin,str);
std::vector<std::string> args = split_str(str);
int out_node = lexical_cast<int,std::string>(args[0]);
int out_port = lexical_cast<int,std::string>(args[1]);
int in_node = lexical_cast<int,std::string>(args[2]);
int in_port = lexical_cast<int,std::string>(args[3]);
backend.connect_nodes(nodes[out_node],nodes[in_node],out_port,in_port);
}
release_pause();
cin.close();
std::cout << "Done loading.. \n";
}
示例3: netif_add_from_spec
void netif_add_from_spec(struct netif **ifs, const char *spec) {
_free_ char *tmp = NULL;
_free_ char **opts = NULL;
if (!spec) return;
tmp = strdup(spec);
fail_if(!tmp, "OOM");
size_t c = split_str(tmp, &opts, ":");
fail_if(!c, "Invalid netif spec '%s': not enough args", spec);
if (if_nametoindex(opts[0])) {
fail_if(c < 2, "Invalid netif spec '%s': not enough args",spec);
netif_add(ifs, MOVE, opts[0], opts[1]);
} else if (!strncmp(opts[0], "macvlan", 8)) {
fail_if(c < 3, "Invalid netif spec '%s': not enough args",spec);
netif_add(ifs, MACVLAN, opts[1], opts[2]);
} else if (!strncmp(opts[0], "ipvlan", 8)) {
fail_if(c < 3, "Invalid netif spec '%s': not enough args",spec);
netif_add(ifs, IPVLAN, opts[1], opts[2]);
} else if (!strncmp(opts[0], "veth", 5)) {
fail_if(c < 3, "Invalid netif spec '%s': not enough args",spec);
netif_add(ifs, VETH, opts[1], opts[2]);
} else {
fail_printf("Invalid netif spec '%s'", spec);
}
}
示例4: bodycallback
size_t bodycallback(char *ptr, size_t size, size_t nmemb, void *userdata) {
char* pstr = (char *)ptr;
replace_char(pstr, '\r', ':');
char **rows = split_str(pstr, '\n');
if (rows == NULL || rows[0] == NULL) {
free(rows);
return nmemb*size;
}
int i = 0;
for (i = 0; rows[i]; i++) {
#ifdef DEBUG
fprintf(stderr, "Read body line: %s\n", rows[i]);
#endif
BODY *curbody = (BODY *) malloc(sizeof(BODY) + strlen(rows[i]) + 1);
curbody->row = (char *) ((char*)curbody + sizeof(BODY));
strcpy(curbody->row, rows[i]);
curbody->next = body;
body = curbody;
}
free(rows);
return nmemb*size;
}
示例5: _diypy3__binary_tree
static PyObject *
_diypy3__binary_tree(PyObject *self, PyObject *args)
{
int order;
char *bt_str;
char *str_slice_rec[BT_MAXSIZE];
BTNODE *T;
if (!PyArg_ParseTuple(args, "is", &order, &bt_str))
return NULL;
split_str(bt_str, str_slice_rec);
temp_rec = str_slice_rec;
pre_order_create(&T);
printf("binary tree initialized\n");
switch (order) {
case 0:
pre_order_visualize(T);
indent = 0;
break;
default:
PyErr_SetString(PyExc_ValueError,
"Unrecognised flag given");
return NULL;
}
Py_RETURN_NONE;
}
示例6: _diypy3__triplet_sparse_matrix
static PyObject *
_diypy3__triplet_sparse_matrix(PyObject *self, PyObject *args)
{
int mu;
int nu;
int tu;
char *trismx_str;
char *str_slice_rec[TRISMX_MAXSIZE];
TRISMX M;
TRISMX N;
if (!PyArg_ParseTuple(args, "iiis", &mu,
&nu,
&tu,
&trismx_str))
return NULL;
split_str(trismx_str, str_slice_rec);
temp_rec = str_slice_rec;
create_sparse_trismx(&M, mu, nu, tu);
printf("triplet sparse matrix initialized\n");
visualize_trismx(&M);
printf("fast transpose this matrix:\n");
fast_transpose_trismx(&M, &N);
visualize_trismx(&N);
Py_RETURN_NONE;
}
示例7: _diypy3__link_queue
static PyObject *
_diypy3__link_queue(PyObject *self, PyObject *args)
{
int i;
int rec_size;
char *queue_str;
char *str_slice_rec[LNKQ_MAXSIZE];
char *deq;
LNKQ Q;
if (!PyArg_ParseTuple(args, "s", &queue_str))
return NULL;
rec_size = split_str(queue_str, str_slice_rec);
temp_rec = str_slice_rec;
if (!init_queue(&Q))
return NULL;
printf("linked list queue initialized\n");
printf("\n");
for (i = 0; i < rec_size; i++) {
printf("enqueue: %s\n", temp_rec[i]);
enqueue(&Q, temp_rec[i]);
}
while (Q.front != Q.rear) {
printf("\nstatus: ");
show_queue(Q);
dequeue(&Q, &deq);
printf("dequeue: %s\n", deq);
}
printf("\nwarning: empty queue\n");
Py_RETURN_NONE;
}
示例8: perform_cmd
static void perform_cmd(t_client *client, char *cmd)
{
char **tab;
int i;
int n;
tab = split_str(cmd, ' ');
n = 0;
while (tab && tab[n])
n++;
if (n == 0)
{
free_tab(tab);
return ;
}
i = 0;
while (i < COMMANDS)
{
if (!my_strcmp_case(client->commands[i].str, tab[0]))
{
client->commands[i].func(client, n, tab);
free_tab(tab);
return ;
}
i++;
}
}
示例9: message_training_setup
/**
* One time initializations done when we want to display a new training mission.
*
* This does all the processing and setup required to actually display it, including
* starting the voice file playing
*/
void message_training_setup(int m, int length, char *special_message)
{
if ((m < 0) || !Messages[m].message[0]) { // remove current message from the screen
Training_num_lines = 0;
return;
}
// translate tokens in message to the real things
if (special_message == NULL)
message_translate_tokens(Training_buf, Messages[m].message);
else
message_translate_tokens(Training_buf, special_message);
HUD_add_to_scrollback(Training_buf, HUD_SOURCE_TRAINING);
// moved from message_training_display() because we got rid of an extra buffer and we have to determine
// the number of lines earlier to avoid inadvertant modification of Training_buf. - taylor
training_process_message(Training_buf);
Training_num_lines = split_str(Training_buf, TRAINING_LINE_WIDTH, Training_line_lengths, Training_lines, MAX_TRAINING_MESSAGE_LINES);
Assert( Training_num_lines >= 0 );
if (message_play_training_voice(Messages[m].wave_info.index) < 0) {
if (length > 0)
Training_message_timestamp = timestamp(length * 1000);
else
Training_message_timestamp = timestamp(TRAINING_TIMING_BASE + strlen(Messages[m].message) * TRAINING_TIMING); // no voice file playing
} else
Training_message_timestamp = 0;
}
示例10: seek_to_regname
static bool seek_to_regname(FILE *f, const char *regname)
{
char str[1024];
while (true) {
fpos_t pos;
int r;
r = fgetpos(f, &pos);
if (r)
myerr2("fgetpos failed");
if (!fgets(str, sizeof(str), f))
return false;
char *parts[3] = { 0 };
r = split_str(str, ",", parts, 3);
if (r != 3)
myerr("Failed to parse register description: '%s'", str);
if (strcmp(regname, parts[0]) == 0) {
r = fsetpos(f, &pos);
if (r)
myerr2("fsetpos failed");
return true;
}
if (!seek_to_next_reg(f))
return false;
}
return false;
}
示例11: c_calloc_2
void *_job_proc(void* data)
{
queue_item *job = (queue_item*) data;
char **job_desc = c_calloc_2(10, 30);
int count = split_str(job->job_description, " ", job_desc);
if (count == 0)
{
fprintf(stdout, "This job has some problem!\n");
}
else if (!strcmp(job_desc[0], "srun"))
{
drun_proc(count, job_desc);
}
else if (!strcmp(job_desc[0], "dcancel"))
{
//dcancel_proc(job_origin_desc_left);
}
else if (!strcmp(job_desc[0], "dinfo"))
{
//dinfo_proc(job_origin_desc_left);
};
pthread_exit(NULL);
return NULL;
}
示例12: print_result
void print_result(float *tab, int max)
{
char **tmp;
int degree;
char *reduced_form;
reduced_form = get_reduced_form(tab, max);
ft_putstr("\033[4mReduced form:\033[0;0m");
ft_putendl(ft_strjoin(" ", ft_strjoin(reduced_form, " = 0")));
tmp = split_str(reduced_form);
degree = get_degree(tmp);
ft_putendl(ft_strjoin("Polynomial degree: ", ft_itoa(degree)));
if (!ft_strcmp(reduced_form, "0"))
ft_putendl("\033[32mAll real numbers are solution.");
else if (!check_all_tab(tab, max))
{
ft_putendl("\033[31mThere is no solution.");
return ;
}
else if (degree > 2)
print_error(3);
else if (degree == 0 || degree == 1)
print_result3(tab, degree);
else if (degree >= 2)
print_result4(tab);
do_mlx(tab);
}
示例13: GetOption
int GetOption (char *str, char *option, int option_len, char *value,
int val_len)
{
char *argv[2];
char key [MENU_TITLE_BUF_LEN +1] = {0};
char val [VALUE_LEN +1] = {0};
char *p;
int argc;
argv[0] = key;
argv[1] = val;
//split string to two part,key and value ,splited by SPACE or TAB
argc = split_str (str, argv);
//if split to two part, return 2.
if( argc < 2 )
return -1;
//remove SPACE and TAB from key and val header and tail.
p = trim (key);
//copy to buffer.
strncpy (option, p, option_len - 1);
p = trim (val);
//remove comment data from string.
remove_comment(p);
strncpy (value, p, val_len -1);
return 0;
}
示例14: get_arg
/*********************************************************************
* 文字列 *buf から、パラメータを読み取り、( adrs , memcnt ) を決める
*********************************************************************
*/
int get_arg(char *buf)
{
arena = AREA_RAM;
if(*buf == 'p') {
buf++; arena = AREA_PGMEM;
}else
if(*buf == 'r') {
buf++; arena = AREA_EEPROM;
}
memcnt = 64;
adrs2 = (-1);
buf = sp_skip(buf);
if(*buf==0) return 0;
arg_cnt = split_str(buf,',',arg_ptr);
scan_args(arg_cnt);
if(arg_cnt>=1) {
adrs = arg_hex[0];
}
if(arg_cnt>=2) {
adrs2 = arg_hex[1];
if(adrs2 != (-1) ) {
memcnt = adrs2 - adrs + 1;
}
if( memcnt < 0) {
memcnt = adrs2;
}
}
return arg_cnt;
}
示例15: fopen
struct reg_desc *find_reg_by_address(const char *regfile, uint64_t addr)
{
char str[1024];
FILE *f = fopen(regfile, "r");
ERR_ON_ERRNO(f == NULL , "Failed to open regfile %s", regfile);
if (!seek_to_regaddr(f, addr))
return NULL;
if (!fgets(str, sizeof(str), f))
ERR("Failed to parse register");
char *parts[3] = { 0 };
int r = split_str(str, ",", parts, 3);
ERR_ON(r != 3, "Failed to parse register description: '%s'", str);
struct reg_desc *reg;
reg = malloc(sizeof(struct reg_desc));
memset(reg, 0, sizeof(*reg));
reg->name = strdup(parts[0]);
reg->offset = strtoull(parts[1], NULL, 0);
reg->width = strtoul(parts[2], NULL, 0);
parse_reg_fields(f, reg);
fclose(f);
return reg;
}