0

Why is this program a mistake? [5]

Could anyone explain it to me why the first code (the bugged one) gives error in codecoach challenge output, although the result is same as expected output (from 1st and 2nd test case output)? https://sololearn.com/compiler-playground/cZMbZukJGQx3/?ref=app https://sololearn.com/compiler-playground/c5IsyCj1SaWf/?ref=app

26th Sep 2024, 3:49 PM
Celvien Kurniawan
Celvien Kurniawan - avatar
7 Answers
+ 2
Celvien Kurniawan remember you actually have to work with both types of YouTube links the long version ie ... https://www.youtube.com/watch?v=RRW2aUSw5vU and the shorter version ie ... youtu.be/RRW2aUSw5vU Here is the complete Task: Create a program that parses through a link, extracts and outputs the YouTube video ID. Input Format: A string containing the URL to a YouTube video. The format of the string can be in "https://www.youtube.com/watch?v=kbxkq_w51PM" or the shortened "https://youtu.be/KMBBjzp5hdc" format. Output Format: A string containing the extracted YouTube video id. Sample Input: https://www.youtube.com/watch?v=RRW2aUSw5vU Sample Output: RRW2aUSw5vU
26th Sep 2024, 4:36 PM
BroFar
BroFar - avatar
+ 2
Celvien Kurniawan the first code works while the second is looking for a number "%s" *p remove the * just p
26th Sep 2024, 4:58 PM
BroFar
BroFar - avatar
+ 1
Celvien Kurniawan change char s[250], to char s[500], you also didn't allow enough here the string is [493]
26th Sep 2024, 4:53 PM
BroFar
BroFar - avatar
+ 1
BroFar eh? But the second code (youtube link finder(true?))is considered correct by codecoach test case, tho. Also i have changed the size of s to 500 in the first code, but the error message (cross mark) still persist.
26th Sep 2024, 5:06 PM
Celvien Kurniawan
Celvien Kurniawan - avatar
+ 1
Oh, thanks For pointing it out (*).
26th Sep 2024, 5:27 PM
Celvien Kurniawan
Celvien Kurniawan - avatar
+ 1
Celvien Kurniawan the first one is picking up the "\0" as a character though it counts the actual characters ( strlen ) in the tail as 11 so it adding "\0" adds 12 or a whitespace the do - while should have been a while loop which will now eliminate the extra whitespace. p++; while (*p != '\0') { printf("%c", *p); p++; }
26th Sep 2024, 5:43 PM
BroFar
BroFar - avatar
0
BroFar yeah, that's why in the code after i use: p=strrchr(s,'='); //for the long URL (cursor setting) i also use: if(p==NULL) p=strrchr(s,'/'); //for the short URL (cursor setting). Then i use p++; to move the cursor to the right so i won't take '/' or '=' in the output string. Then big question for me is... Why the output of the first code is considered mistake (has error) while it has the exact same output like in the second code?
26th Sep 2024, 4:50 PM
Celvien Kurniawan
Celvien Kurniawan - avatar