What does this program do? /* ex07_22.c */ /* what does this program do? */ #inc
ID: 3622192 • Letter: W
Question
What does this program do?/* ex07_22.c */
/* what does this program do? */
#include <stdio.h>
int mystery2( const char *s ); /* prototype */
int main( void )
{
char string[ 80 ]; /* create char array */
printf( "Enter a string: ");
scanf( "%s", string );
printf( "%d ", mystery2( string ) );
return 0; /* indicates successful termination */
} /* end main */
/* What does this function do? */
int mystery2( const char *s )
{
int x; /* counter */
/* loop through string */
for ( x = 0; *s != ''; s++ )
{
x++;
} /* end for */
return x;
} /* end function mystery2 */
Explanation / Answer
please rate - thanks
counts and outputs how many characters are in the input string
/* ex07_22.c */
/* what does this program do? */
#include <stdio.h>
int mystery2( const char *s ); /* prototype */
int main( void )
{
char string[ 80 ]; /* create char array */
printf( "Enter a string: ");
scanf( "%s", string );
printf( "%d ", mystery2( string ) );
return 0; /* indicates successful termination */
} /* end main */
/* What does this function do? */
int mystery2( const char *s )
{
int x; /* counter */
/* loop through string */
for ( x = 0; *s != ''; s++ ) //x is the counter starts at 0
{ //start at 1st element of the input string, and do until you get to the
x++; //null which indicated the end of the array, incrementing x each time
} /* end for */ //through the loop
return x;
} /* end function mystery2 */
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.