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
XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX
I am trying to use sscanf to put them into 2 different chars
wonder if this can be done with sscanf
use this:
sscanf(buffer, "%[^ ] %s",value1, value2);
There is a white space after ^ and another one after ]
sscanf(buffer, "%[^ ] %s",value1, value2);
There is a white space after ^ and another one after ]
ASKER
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 *sample="C4Z2376VC6E4TH9 MC72V74H4BGKT6JF";
char value1[30], value2[30];
sscanf(sample, "%[^ ] %s",value1, value2);
printf ("value1=%s\nvalue2=%s", value1, value2);
ASKER
char buffer[1000];
int nLineCount = 0;
char curdir[MAX_PATH];
GetCurrentDirectory(MAX_PA TH,curdir) ;
char file[MAX_PATH];
sprintf(file,"%s%s",curdir ,"\\keys.t xt");
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(ConsoleOut put::RED," Classic: %s LoD: %s\n", Classic,LoD);
}
infile.close();
int nLineCount = 0;
char curdir[MAX_PATH];
GetCurrentDirectory(MAX_PA
char file[MAX_PATH];
sprintf(file,"%s%s",curdir
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(ConsoleOut
}
infile.close();
ASKER
gives me
Classic: C4Z2376VC6E4TH9MC72V74H4BG KT6JF LoD: MC72V74H4BGKT6JF
Classic: C4Z2376VC6E4TH9MC72V74H4BG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
char Classic[20];
char LoD[20];
fixed all my problems lol thanks =)
char LoD[20];
fixed all my problems lol thanks =)
ASKER
Value1: 2C4Z2376VC6E4TH9MC72V74H4B
from
sscanf(buffer, "%s%s", value1,value2);