I need to parse a string like func1(arg1, arg2); func2(arg3, arg4);. It's not a very complex parsing problem, so I would prefer to avoid resorting to flex/bison or similar utilities.
My first approch was to try to use POSIX C regcomp/regexec or Boost implementation of C++ std::regex. I wrote the following regular expression, which does ...
This is a simple problem, but I can't see it:
char *s = "f 8.649292" ;
double d ;
sscanf( s, "f %f",
printf( "d is %f\n", d ) ;
Why is d not containing the double value 8.649292?
...
I'm trying to convert a string to GUID with sscanf:
GUID guid;
sscanf( "11111111-2222-3333-4455-667788995511", "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
&guid.Data1, &guid.Data2, &guid.Data3,
&guid.Data4[0], &guid.Data4[1], &guid.Data4[2],
&guid.Data4[3], &guid.Data4[4], &guid.Data4[5],
&guid.Da...
For a project I'm trying to read an int and a string from a string. The only problem is sscanf appears to break reading an %s when it sees a space. Is there anyway to get around this limitation? Here's an example of what I'm trying to do:
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char** argv) {
int age;
char* buff...
I have a semi xml formatted file that contains line with the following format:
<param name="Distance" value="1000Km" />
The first char in the string is usually a TAB or spaces.
I've been using the following to try to parse the two strings out (from name and value):
if(sscanf(lineread, "\t<param name=\"%s\" value=\"%s\" />", name, val...
Hi.
sscanf(text, "%s %s", name, company);
parses 'ian mceknis' but it also parses 'ian mceknis' and so on. How can i make this to parse only the first one? It must contain only one space not more.
Thank you.
...
I wrote up a quick memory reader class that emulates the same functions as fread and fscanf.
Basically, I used memcpy and increased an internal pointer to read the data like fread, but I have a fscanf_s call. I used sscanf_s, except that doesn't tell me how many bytes it read out of the data.
Is there a way to tell how many bytes ssc...
Hi
I have a text file like this:
2
A 10 5
B 31 2
C 6 6
I want to read first line number in a variable
and read each line's space separated list of 3 values in 3 variables.
I wrote this code:
iF=fopen(fileName,"r");
fgets(tmp,255,iF);
sscanf(tmp,"%d",&interval);
while(!feof(iF)){
cur=(P *)malloc(sizeof(P));
fgets(tmp,255,i...
Hello,
gcc 4.4.4 c89
What is better to convert a string to an integer value.
I have tried 2 different methods atoi and sscanf. Both work as expected.
char digits[3] = "34";
int device_num = 0;
if(sscanf(digits, "%d", &device_num) == EOF) {
fprintf(stderr, "WARNING: Incorrect value for device\n");
return FALSE;
}
or using a...
Hello, I've some string (char *) in C and using sscanf to tokenize it.
I'm generating C source-code and using sscanf is easiest solution, however there is this problem:
There is regular expression for parameter:
[$]([a-zA-Z0-9_-]{0,122})?[a-zA-Z0-9]
(Starting with $, can contain numbers, letters, '-' and '_', but later two can not b...
I wrote a simple log file for my website that is in the following format:
TIME: "..." IP: "..." HOST: "..." UA: "..."
And wanted to parse through it with sscanf as part of an exercise. My code was roughly like this, which was run on each line of the log:
list($time, $ip, $host, $ua) = sscanf("TIME: %s IP: %s HOST: %s UA: %s", $line)...
Hello
I haw an appl, which do a error:
/lib/libc.so.6: version `GLIBC_2.7' not found
But the only symbol it needs from glibc 2.7 is
__isoc99_sscanf@@GLIBC_2.7
I want to write a small 1 function "library" with this symbol as alias to __sscanf()
How can I do this with gcc/ld?
My variant is not accepted because "@@" symbols
int ...
I was wondering whether there's a better way of doing this; say we read stdin to a string using fgets() where the string includes a total of n integers (e.g. 5 16 2 34 for n = 4), what would be the best way of extracting them? There has got to be a better way than this hack:
for (i=0, j=0; i<n; ++i, j+=pos)
sscanf(string+j, "%d%n",...
I want to read in a string and parse it with sscanf. Although i don't want to read in any spaces in the beginning.
Sample string.
@a Bear Tiger
sscanf(strLine, "@%1s %64s %64s", dir, name1, name2);
I have that.
Problem is if the line goes in as say
@a Bear Tiger
Should be:
@a Bear Tiger
that it will want to read in th...
Is there a good way to loop over a string with sscanf?
Let's say I have a string that looks like this:
char line[] = "100 185 400 11 1000";
and I'd like to print the sum. What I'd really like to write is this:
int n, sum = 0;
while (1 == sscanf(line, " %d", &n)) {
sum += n;
line += <number of bytes consumed by sscanf>
}
but t...
I've been trying to get sscanf to recognize a fairly simple format using character classes. I've noticed that when I provide sscanf with a char* to match the character class it overwrites the previous byte also as if it expected a pointer to 2 bytes.
A simplified version of what I'm trying to accomplish:
#include <stdio.h>
int main(vo...