Hi can do this Its C NOT C thank u 720 What does this progra

Hi

can do this

It\'s C NOT C++ thank u

7.20 What does this program do? /ex07 20.c / 2/*what does this program do?*/ #incl ude sint mystery2 const char *s ); * prototype */ T int main void ) int main( void ) char string 80 1 /* create char array */

Solution

What does this code do?

It reads a string and in return it prints the number of character in given string

here is code with expaination in comments:

#include <stdio.h>
int mystery2(const char *s);
int main(){
int w,h,i;
char string[80];
// read the string
printf(\"Enter a string: \");
scanf(\"%s\",string);
printf(\"%d\ \",mystery2(string));

return 0;
}

int mystery2(const char *s)
{
int x;
/* loops untill the end of string
where \'\\0\' denotes end of string */

for(x=0;*s != \'\\0\';s++)
{
// count the number of character
x++;
}
return x;
}

Output:

Enter a string: asdlkfasdfasdf                                                                                                       

14

Hi can do this It\'s C NOT C++ thank u 7.20 What does this program do? /ex07 20.c / 2/*what does this program do?*/ #incl ude sint mystery2 const char *s ); * p

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site