Last active
January 15, 2023 18:53
-
-
Save coinconclusive/7ba04129af2f4342f6cb9420430c0e47 to your computer and use it in GitHub Desktop.
obfuscated integer and float parsing in c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this compiles with -Wall -Wpedantic -Werror // | |
int s2i(char**s,int*n){ | |
int z=1;for(*n=0;**s>47 | |
;z*=10)*n=*n*10+*(*s)++ | |
-48;;return z;}void s2f | |
(char**s,float*f){int n | |
,z;s2i(s,&n);*f=n;+**s^ | |
46?0:(*f+=(++*s,z=s2i(s | |
,&n),(n+0.f)/z));}/*a*/ | |
// example usage: // | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int main() { | |
char s1[] = "123.456"; | |
char *s2 = malloc(8); | |
memcpy(s2, s1, sizeof(s1)); | |
char *s3 = s2; | |
float x; | |
s2f(&s3, &x); | |
printf("%s -> %f\n", s2, x); | |
free(s2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment