C分流字符数组到不同的变量 [英] C split a char array into different variables

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

问题描述

在C哪能由分隔符分隔字符数组?或者是更好的操纵字符串?都有些什么好的C字符处理函数?


解决方案

 #包括LT&;&string.h中GT;
#包括LT&;&stdio.h中GT;
诠释的main()
{
    字符输入[16] =ABC D;
    字符* P;
    p值= strtok的(输入,,);    如果(p)的
    {
    的printf(%S \\ n,p)的;
    }
    p值= strtok的(NULL,,);    如果(p)的
           的printf(%S \\ n,p)的;
    返回0;
}

你可以看看这个程序。首先,你应该使用的strtok(输入,)。输入你想spilt.Then您使用的strtok字符串(NULL,)。如果返回值是true,则可以打印另一组。

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;
}

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天全站免登陆