+ 3

*DAILY CHALLENGE* : Write a sscanf like function.

The function gets a string s and a string p (pattern) and returns an array of variables. The pattern can contain: - %d for integer AND double - %s for string - %c for character - any normal asci-char example 1: p = "%c'am %d" s = "I'am 25" result = sscanf(s,p) = ['I',25] example 2: p = "good %s!" s = "good night!" result = sscanf(s,p) = ["night"] info: - If s doesn't match p -> return an empty array - If you can't return arrays with different types store the values as strings and return a string array!

21st Aug 2017, 3:30 PM
Julian Fechner
Julian Fechner - avatar
17 Antworten
+ 1
This took me...about 3 straight hours. And I TOTALLY FORGOT TO ACCOUNT FOR %D ACCEPTING FLOATS. But...it works. It Goddamn works lol. %s only takes alpha chars that can be divided by single spaces into consideration. Spaces, unless %s is being applied are ignored and must correspond to both strings in positioning. All text that doesn't correspond to %d, %s and %c are ignored, and must correspond in positioning, or it fails and returns an empty array. For example; "this is returned 25 ignored #" and "%s %d ignored %c" will pass, however, "this is returned 25 ignored #" and "%s%d ignored %c" will fail, because there is not a space in between %s and %d. EDIT: %d works for float input now. Woot! https://code.sololearn.com/cUu9QopM2ZL5/?ref=app
22nd Aug 2017, 12:34 PM
Vari93
Vari93 - avatar
+ 5
had a hard weekend .... ^^
21st Aug 2017, 3:48 PM
Julian Fechner
Julian Fechner - avatar
+ 4
@sayan chandran ---> GOOD QUESTION! %d, %s and %c aren't allowed in s.
21st Aug 2017, 5:13 PM
Julian Fechner
Julian Fechner - avatar
+ 3
theres a question i want to ask @ JULIAN @ 1st eg:::: suppose the string is--> hi 2 meet %d so if the pattern is -----> hi %d %s %d the last %d (in p) is not as the pattern its because the string have it... 2nd eg:::: now here is the catch again suppose the string is--> hi 2 meet %s so if the pattern is -----> hi %d %s %s the last %s (in p) is as detecting of a string not because in s its there.. how the compiler will understand 1st example is not a error even the 2nd one is also not..???????? how will the compiler know if the pattern as p have %d/%s/%c as detection or as the input string have it????
21st Aug 2017, 4:16 PM
sayan chandra
sayan chandra - avatar
+ 1
EXAMPLE 3: s = "nice 2 meet you!" p = "nice %d %s%c" result = sscanf(s,p) = [2, "meet you", '!'] EXAMPLE 4: s = "ok" p = "%d" res = sscanf(s,p) = [ ] AND PLEASE DO NOT USE ANY BUILT-IN FUNCTION LIKE FORMAT(etc)!!!
21st Aug 2017, 3:41 PM
Julian Fechner
Julian Fechner - avatar
+ 1
regex !
21st Aug 2017, 6:34 PM
VcC
VcC - avatar
+ 1
MY NEW *DAILY CHALLENGE*: GIVE IT A TRY!!! https://www.sololearn.com/discuss/647083/?ref=app
22nd Aug 2017, 10:22 AM
Julian Fechner
Julian Fechner - avatar
23rd Aug 2017, 9:40 AM
Julian Fechner
Julian Fechner - avatar
0
different challenge on the way TUESDAY TALES https://www.sololearn.com/discuss/646010/?ref=app
21st Aug 2017, 7:23 PM
sayan chandra
sayan chandra - avatar
0
22nd Aug 2017, 9:17 PM
ysraelcon
ysraelcon - avatar
23rd Aug 2017, 8:16 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
23rd Aug 2017, 10:34 AM
Julian Fechner
Julian Fechner - avatar
26th Aug 2017, 1:52 PM
Julian Fechner
Julian Fechner - avatar
0
vote for your favorite coding language: https://code.sololearn.com/WJqfkcTEguBe/?ref=app
4th Oct 2017, 7:04 PM
Julian Fechner
Julian Fechner - avatar
7th Oct 2017, 12:12 PM
Julian Fechner
Julian Fechner - avatar
- 1
<html> <head> <title> Login page </title> </head> <body> <h1 style="font-family:Comic Sans Ms;text-align="center";font-size:20pt; color:#00FF00;> Simple Login Page </h1> <form name="login"> Username<input type="text" name="userid"/> Password<input type="password" name="pswrd"/> <input type="button" onclick="check(this.form)" value="Login"/> <input type="reset" value="Cancel"/> </form> <script language="javascript"> function check(form)/*function to check userid & password*/ { /*the following code checkes whether the entered userid and password are matching*/ if(form.userid.value == "myuserid" && form.pswrd.value == "mypswrd") { window.open('target.html')/*opens the target page while Id & password matches*/ } else { alert("Error Password or Username")/*displays error message*/ } } </script> </body> </html>
22nd Aug 2017, 6:54 AM
Rasheed Ghoto
Rasheed Ghoto - avatar
- 1
HERES THE NEW CHALLENGE... CHECK IT OUT FRIENDS https://www.sololearn.com/discuss/653982/?ref=app
24th Aug 2017, 6:51 PM
sayan chandra
sayan chandra - avatar