+ 1
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
12 Respuestas
+ 4
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++;
}
+ 4
Celvien Kurniawan the first code works while the second is looking for a number "%s" *p remove the * just p
+ 3
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
+ 2
Celvien Kurniawan change
char s[250], to char s[500], you also didn't allow enough here the string is [493]
+ 2
Amanuel BeAman welcome to Sololearn but your comment is offtopic for this thread please search the question and answer forum.
https://www.sololearn.com/discuss/1316935/?ref=app
https://www.sololearn.com/discuss/3021159/?ref=app
+ 2
Celvien Kurniawan
Do you really need a while loop to display the string?
#include <stdio.h>
#include <string.h>
int main() {
char link[500];
scanf("%s", link);
char* vidId = strrchr(link,'=');
puts((vidId) ? ++vidId : (strrchr(link,'/')+1));
}
+ 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.
+ 1
Oh, thanks For pointing it out (*).
+ 1
I see. Thanks for the info. I finally understand why.
+ 1
Bob_Li wow. It can be made that way... Awesome.
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?
0
Why isn't add image to our web this app for our website is not show images.