Link to home
Start Free TrialLog in
Avatar of WackoMike
WackoMike

asked on

sscanf spliting

I have a string like this

XXXXXXXXXXXXXXXX   XXXXXXXXXXXXXXXXXXX

I am trying to use sscanf to put them into 2 different chars

wonder if this can be done with sscanf
Avatar of WackoMike
WackoMike

ASKER

when I do it I get
Value1: 2C4Z2376VC6E4TH9MC72V74H4BGKT6JF Value2: MC72V74H4BGKT6JF
from
sscanf(buffer, "%s%s", value1,value2);
use this:
sscanf(buffer, "%[^ ] %s",value1, value2);

There is a white space after ^ and another one after ]
yeah did that aswell I get the same results there are 3 spaces
Sorry, I don't undestand what you mean. This works:

char *sample="C4Z2376VC6E4TH9   MC72V74H4BGKT6JF";
char value1[30], value2[30];

sscanf(sample, "%[^ ] %s",value1, value2);
printf ("value1=%s\nvalue2=%s", value1, value2);
char buffer[1000];
            int nLineCount = 0;
            char curdir[MAX_PATH];
            GetCurrentDirectory(MAX_PATH,curdir);
            char file[MAX_PATH];
            sprintf(file,"%s%s",curdir,"\\keys.txt");
            fstream infile;
            infile.open(file, ios::in);
            char Classic[16];
            char LoD[16];
            char Key;
            
            while(!infile.eof() && !infile.fail())
            {
                  infile.getline(buffer, sizeof(buffer));
                  sscanf(buffer, "%[^ ] %s",Classic, LoD);
                  
                  Output->WriteEx(ConsoleOutput::RED,"Classic: %s LoD: %s\n", Classic,LoD);
          
                  
            }

            infile.close();
gives me

Classic: C4Z2376VC6E4TH9MC72V74H4BGKT6JF LoD: MC72V74H4BGKT6JF
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
char Classic[20];
char LoD[20];

fixed all my problems lol thanks =)