Home > Back-end >  Please, save the children, study for three hours
Please, save the children, study for three hours

Time:09-20

Write a function strlen function, application results are as follows:
The input string s1:
China
Length=5
Please do not alter the contents of the main program main and other functions, only fill in the curly braces of strlen () function with written several statements,
Note: partial source program are given as follows:
# include & lt; Stdio. H>
Int strlen (char STR [])
{




}
Void main ()
{char s1 [80];
Printf (" input string s1: \ n ");
Gets (s1);
Printf (" length=% d \ n ", strlen (s1));
}

CodePudding user response:

You must pretend to think, ah...
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
int i;
for(i=0; STR [I]; I++);
return i;

CodePudding user response:

reference 1st floor coo135 response:
you must pretend to think, ah...
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
int i;
for(i=0; STR [I]; I++);
return i;

This this this...

CodePudding user response:

reference 1st floor coo135 response:
you must pretend to think, ah...
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
int i;
for(i=0; STR [I]; I++);
return i;

Don't need the scanf...

CodePudding user response:

reference zege666 reply: 3/f
Quote: refer to 1st floor coo135 response:
you must pretend to think, ah...
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
int i;
for(i=0; STR [I]; I++);
return i;

This this this...


A one hour ~ ~ ~
VC strlen is written like this:
Const char * eos=STR;
While (* eos++);
Return (eos - STR - 1);

CodePudding user response:

reference 5 floor coo135 reply:
Quote: refer to the third floor zege666 response:

Quote: refer to 1st floor coo135 response:
you must pretend to think, ah...
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
int i;
for(i=0; STR [I]; I++);
return i;

This this this...


A one hour ~ ~ ~
VC strlen is written like this:
Const char * eos=STR;
While (* eos++);
Return (eos - STR - 1);

Touches my knowledge blind area, we haven't learned pointer

CodePudding user response:

Write a simple
 
Int I=0
While (STR [I]!='\ 0')
{
i++;
}
return i;

CodePudding user response:

Beginners ~ ~ string '/0' end is NULL is 0, then according to the number to the '/0, + 1 + 1 + 1, finally returned to the count
  • Related