typedef union
{
uint ui[4];
} md5hash;
void main(void)
{
int opt;
while ((opt = getopt(argc, argv, "c:t:s:h:")) != -1) {
switch (opt) {
case 'h':
hash = optarg;
break;
default: /* '?' */
exit(EXIT_FAILURE);
}
}
md5hash hash;
sscanf(hash, "%x%x...
Some background: If I wanted to use for, for instance, scanf() to convert a string into a standard integer type, like uint16_t, I’d use SCNu16 from <inttypes.h>, like this:
#include <stdio.h>
#include <inttypes.h>
uint16_t x;
char *xs = "17";
sscanf(xs, "%" SCNu16, &x);
But a more uncommon integer type like pid_t does not have any suc...
int main(void) {
char tmp, arr[100];
int i, k;
printf("Enter a string: ");
scanf_s("%s", arr);
for ( k = 0, i = (strlen(arr) - 1); k < (int) (strlen(arr) / 2); --i, ++k) {
tmp = arr[k];
arr[k] = arr[i];
arr[i] = tmp;
}
puts(arr);
return 0;
}
I know that there is so...
I have a problem that sscanf solves (extracting things from a string). I don't like sscanf though since it's not type-safe and is old and horrible. I want to be clever and use some more modern parts of the C++ standard library. What should I use instead?
...
Hi
I'm parsing some CSV data in C for the purposes of a Ruby extension. In order to pull out the data from each row I'm using sscanf as follows:
char* line = RSTRING_PTR(arg);
double price;
double volume_remaining;
unsigned int type_id, range, order_id, volume_entered, minimum_volume, duration, station_id, region_id, solar_syst...
I have an application written in C that reads text messages from a modem using AT commands. A typical AT response from the modem looks like this:
+CMGL: 1,"REC READ","+31612123738",,"08/12/22,11:37:52+04"
The code is currently set up to only retrieve the id from this line, which is the first number, and it does so using the following ...
I'm given a string hex_txt containing a 4 digit hex number in the way outlined in the code, split up in two array entries. I need to convert it to decimal. The following is the way I'm doing it.
unsigned char hex_txt[] = "\xAB\xCD";
unsigned char hex_num[5];
unsigned int dec_num;
sprintf(hex_num, "%.2x%.2x", (int)hex_txt[0], (int)hex_t...
i have this string:
12 4 the quick 99 -1 fox dog \
what i want in my program:
myArray[] = {12, 4, 99, -1};
how i do a multiple number scanning?
...
I have a comma separated string which might contain empty fields. For example:
1,2,,4
Using a basic
sscanf(string,"%[^,],%[^,],%[^,],%[^,],%[^,]", &val1, &val2, &val3, &val4);
I get all the values prior to the empty field, and unexpected results from the empty field onwards.
When I remove the expression for the empty field from th...
Hi,
I'm passing as input to my program: "<param value=s/>"
I use this code:
char character[1];
sscanf(data, "<param value=%c/>", &character);
printf("%c", character);
However the output seems to be "s/>" instead of only "s" char.
what's wrong here?
...
Hello, I'm having trouble extracting the timings from a .srt (subtitle) file and writing it to another file called output.srt. When i run the following i get some funky stuff written onto the output file.
// where hr=hours,mn=minutes,sc=seconds,ms=mili seconds
#include <stdio.h>
#define LINES 50
#define CHARAC 80
int main(void){
FI...
I was just spending my whole day debugging a random bug when i finally realized the Problem was sscanf being called from multiple threads.
I confirmed by running the following code which works as expected on Snow Leopard but produces very strange results on my iphone with os 3.1.2. It also works fine in the Simulator.
On the iPhone the...
Hi,
This doesn't work:
list($value) = sscanf('foo.bar','%s.bar');
echo $value; //foo.bar
While this does:
list($value) = sscanf('foo bar','%s bar');
echo $value; //foo
Any suggestions are really appreciated.
Thanks.
...
Hi,
this is my c code that reads a list of URLs from a file , and tries to separate the various parts of the URL.. This is just rough parsing , i'm not bothered about special cases.. I guess there is some fault with the sscanf() statement , when i run this , i get " segmentation FAULT" .. and moreover , the full url is being assigned t...
I'm looking for an equivalent to sscanf() in Python. I want to parse /proc/net/* files, in C I could do something like this:
int matches = sscanf(
buffer,
"%*d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %*X %*X:%*X %*X:%*X %*X %*d %*d %ld %*512s\n",
local_addr, &local_port, rem_addr, &rem_port, &inode);
I thought at ...
Quick question, What have I done wrong here. The purpose of this code is to get the input into a string, the input being "12 34", with a space in between the "12" and "32" and to convert and print the two separate numbers from an integer variable known as number. Why doesn't the second call to the function copyTemp, not produce the value...
I've been tasked with updating a function which currently reads in a configuration file from disk and populates a structure:
static int LoadFromFile(FILE *Stream, ConfigStructure *cs)
{
int tempInt;
...
if ( fscanf( Stream, "Version: %d\n",&tempInt) != 1 )
{
printf("Unable to read version number\n");
return 0;
}
c...
I have a function that makes a series of calls to sscanf() and then, after each, updates the string pointer to point to the first character not consumed by sscanf() like so:
if(sscanf(str, "%d%n", &fooInt, &length) != 1)
{
// error handling
}
str+=length;
In order to clean it up and avoid duplicating this several times over, i'd l...
Hi, I have a text file of associated numbers i.e;
1 2 2
3 2 1
3 4 3
Each line is a seperate piece of information, as such I am trying to read it in one line at a time and then seperate it into the 3 numbers but sscanf isn't doing what I expect it to.
char s[5];
char e[5];
char line[100];
int d;
fgets(line, sizeof(line), inFile);
ssc...
When I compile a simple Hello World! program that uses the sscanf function on my local Debian lenny x64, it works. But when I upload the same program to the server running CentOS x86, it will not work. If I do not use sscanf, then the program works on both computers.
gcc -std=c99 -O2 -pipe -m32
If I compile it with sscanf but without -...