Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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


C#
//
        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++">
Posted
Comments
CPallini 15-Dec-14 3:00am    
Could you please provide a sample input (and possibly the expected output)?

1 solution

Don't use fscanf if you are going to tokenize the input. Use fgets or similar function to read the entire line.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900