C
chessc4c6
I'm taking a C++ course right now and my homeowrk was to create a
strlen function(even though it already existed) and have main call it
and read a string to give its length.
The first Version was supposed to have the prototype:
long strlen(char s1[])
and a for()loop and a array representing the string will be used. So I
came up with:
long strlen(char s1[]){
long counter;
for(counter=0;s1[counter] != '\0'; counter++);
return counter;
}
void main(){
long strlen(char s1[]);
cout<<"The length of the string COMPUTER SCIENCE is : "<<
strlen("COMPUTER SCIENCE")<<endl;
}
So the next step is making the prototype:
long strlen(char *s1);
using a while()loop and a pointer representing the string should be
used. Now I was given the hint of changing the fucntion by doing
something like "s1+1"...but am not really sure at all where to begin.
Help would be appreciated.
strlen function(even though it already existed) and have main call it
and read a string to give its length.
The first Version was supposed to have the prototype:
long strlen(char s1[])
and a for()loop and a array representing the string will be used. So I
came up with:
long strlen(char s1[]){
long counter;
for(counter=0;s1[counter] != '\0'; counter++);
return counter;
}
void main(){
long strlen(char s1[]);
cout<<"The length of the string COMPUTER SCIENCE is : "<<
strlen("COMPUTER SCIENCE")<<endl;
}
So the next step is making the prototype:
long strlen(char *s1);
using a while()loop and a pointer representing the string should be
used. Now I was given the hint of changing the fucntion by doing
something like "s1+1"...but am not really sure at all where to begin.
Help would be appreciated.