+ 1

Why the sololearn app say my program is wrong for this project in c language

You are robbing a bank, but you’re not taking everything. You are looking for a specific item in the safety deposit boxes and you are going to drill into each one in order to find your item. Once you find your item you can make your escape, but how long will it take you to get to that item? Task Determine the amount of time it will take you to find the item you are looking for if it takes you 5 minutes to drill into each box. Input Format A string that represent the items in each box that will be drilled in order (items are separated by a comma), and secondly, a string of which item you are looking for. Output Format An integer of the amount of time it will take for you to find your item. Sample Input 'gold,diamonds,documents,Declaration of Independence,keys' 'Declaration of Independence' Sample Output 20 Hier ist my programm: https://code.sololearn.com/cXe8w3ca2kup/?ref=app

21st Jan 2022, 6:18 AM
Aboubakar
Aboubakar - avatar
3 odpowiedzi
+ 2
For future requests for help, please: - use descriptive variable names - comment the code, to make it easier understood - format well. That will make it much easier to get through your code. Thank you :) Now, there are a lot of issues, and I did not read through the entire code. For starters, the key size may be too short. There are definitely items longer than 15 chrs in the vaults. But it may be that 15 chars suffice to identify them unambiguously. Maybe that wa your strategy. Line 22: I believe you want sizeof(char*) What you do in the beginning appears to be what the builtin function 'strtok' does. Lookup that function in the documentation: https://man7.org/linux/man-pages/man3/strtok.3.html The way you copy over parts of the string into your array is wrong. The strcpy function copies until it reaches the string termination character - and that is missing in your case. There is a strncpy function you can use if you count the number of characters between the commas. But that is actually not important at all if you choose to use strtok instead ;) That is about as far as I have gotten. You may want to rework your code and head back here if you run into further trouble :) Good Luck!
21st Jan 2022, 7:32 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 1
Thanks a lot
21st Jan 2022, 7:41 AM
Aboubakar
Aboubakar - avatar
0
You're welcome :)
21st Jan 2022, 7:42 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar