如何读取一行中的分隔文本变量 [英] how to read delimited text variables in a line

查看:98
本文介绍了如何读取一行中的分隔文本变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码来读取三个以空格分隔的变量(:

mm / s米kg



但是我的代码只能正确读取第一个变量ppv。



请帮助我让空格分隔符适用于任何空间





I am trying to use the following code to read three space-delimited variables (:
mm/s meter kg

but my code only read the first variable ppv correctly.

Please help me to get the space-delimiter working for any space


//
        char  string1[600]=" ";
        char *next_token1;
        char seps1[] = " ";
        CString ppv="";
        CString size="";
        CString dist="";
//
        fscanf_s(f_ptr2,"%s\n",string1,90);
        ppv = strtok_s(string1, seps1,&next_token1);
        size = strtok_s(NULL, seps1,&next_token1);
        dist = strtok_s(NULL, seps1,&next_token1);
<pre lang="c++"><pre lang="text"><pre lang="c++"><pre lang="c++">

推荐答案

请勿使用 fscanf 如果要对输入进行标记化。使用 fgets 或类似函数来读取整行。
Don't use fscanf if you are going to tokenize the input. Use fgets or similar function to read the entire line.


这篇关于如何读取一行中的分隔文本变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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