C 将一个字符数组拆分为不同的变量 [英] C split a char array into different variables

查看:35
本文介绍了C 将一个字符数组拆分为不同的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 C 中如何用分隔符分隔字符数组?还是操纵字符串更好?有哪些好的 C 字符操作函数?

In C how can I separate a char array by a delimiter? Or is it better to manipulate a string? What are some good C char manipulation functions?

推荐答案

#include<string.h>
#include<stdio.h>
int main()
{
    char input[16] = "abc,d";
    char *p;
    p = strtok(input, ",");

    if(p)
    {
    printf("%s\n", p);
    }
    p = strtok(NULL, ",");

    if(p)
           printf("%s\n", p);
    return 0;
}

你可以看看这个程序.首先你应该使用 strtok(input, ",").input 是你想要拆分的字符串.然后你使用 strtok(NULL, ",").如果返回值为 true ,则可以打印其他组.

you can look this program .First you should use the strtok(input, ",").input is the string you want to spilt.Then you use the strtok(NULL, ","). If the return value is true ,you can print the other group.

这篇关于C 将一个字符数组拆分为不同的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆