Does anyone know how to write a function that counts length of an array given like in example ?
cout << length(argv[1]) << endl;
I've tried somethig like this but it says that there can't be function lentgh then.
for(int i = 0; myStrChar[i] != '\0'; i++)
{
count++;
}
EDIT1: Here is the rest of code :
#include <iostream>
#include<cstring>
using namespace std;
int i;
int length()
{
for(int i = 0; myStrChar[i] != '\0'; i++)
{
count++;
}
}
int main()
{
cout << "Hello world!" << endl;
cout << "length of first text: ";
cout << length(argv[1]) << endl;
char tab[255] = {"Ana has a cat"};
EDIT2: Now I did something like this but it puts out 108 as length of text
char argv[]="ana has a cat";
int length(char l)
{
int cou= 0;
for(int i = 0; i!=0; i++)
{
cou++;
return cou;
}
}