+ 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!
18 ответов
+ 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
+ 5
had a hard weekend .... ^^
+ 4
@sayan chandran
---> GOOD QUESTION!
%d, %s and %c aren't allowed in s.
+ 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????
+ 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)!!!
+ 1
regex !
+ 1
MY NEW *DAILY CHALLENGE*:
GIVE IT A TRY!!!
https://www.sololearn.com/discuss/647083/?ref=app
+ 1
NEW DAILY CHALLENGE FOR YOU:
https://www.sololearn.com/discuss/649970/?ref=app
0
different challenge on the way
TUESDAY TALES
https://www.sololearn.com/discuss/646010/?ref=app
0
this works with the examples : https://code.sololearn.com/Wr9MQ6sBhJOf/?ref=app
0
Work with all your tests
https://code.sololearn.com/cSD8yFboHoZU/?ref=app
0
ANOTHER MINI-CHALLENGE HERE:
https://www.sololearn.com/discuss/650079/?ref=app
0
NEW *DAILY CHALLENGE* HERE:
https://www.sololearn.com/discuss/659673/?ref=app
0
vote for your favorite coding language:
https://code.sololearn.com/WJqfkcTEguBe/?ref=app
0
my mew challenge:
https://www.sololearn.com/discuss/770421/?ref=app
- 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>
- 1
HERES THE NEW CHALLENGE...
CHECK IT OUT FRIENDS
https://www.sololearn.com/discuss/653982/?ref=app