List of all available Websheets
Viewing cpp/cstrings/strlen by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | Define a function <tt>strlen</tt> that takes a single character array as input, <tt>src</tt>. <tt>src</tt> is a null-terminated character array. Return the number of non-null characters in the string. Example: "hi" should return 2 while "" should return 0. |
Engine | |
Template / Reference solution |
using namespace std; // return the length (# non-null characters) of the C-string // (null-terminated character array) passed as an argument \[ REDACTED ]\ strlen(\[ REDACTED ]\) { \[ REDACTED ]\ } int main() { char str1[] = "abcdefghijklmnopqrstuvwxyz"; char str2[] = "len"; char str3[1] = ""; cout << strlen(str1) << endl; cout << strlen(str2) << endl; cout << strlen(str3) << endl; return 0; } |
C++ test suite json list of stdin/args tests e.g. [{"stdin":"hi", "args":["4", "5"]}, {"stdin":"noargs"}] to just run once with no input use [{}] | [{}] |
Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.