answersLogoWhite

0

// returns the length of str

int strLength(const char* str) {

int length = -1;

// we know that all strings in C must be null-terminated, so when a character of

// str is the null character, we have reached the end

while(str[++length]);

return length;

}

User Avatar

Wiki User

16y ago

What else can I help you with?

Related Questions

Program to find the size of the string without using string functions?

You can't. If you want to find the length of a String object, you must use at least one of the String methods. Simply iterate over your char* and count the number of characters you find before you reach the null character . int strLength(const char* str) { int length = 0; // take advantage of the fact that all strings MUST end in a null character while( str[length] != '\0' ) { ++length; } return length; }


What is the functions of a ruler?

to measture the length of objects


Is there any program in c to count length of a string without using Built in functions and looping statements?

Yes, but never ever do it like this in real life: size_t mystrlen (const char *s) { if (s==NULL *s=='\0') return 0; else return 1 + mystrlen (s+1); }


Why functions use in c language?

Because you have to: any executable statement in C must belong to one function or another; there mustn't be executable statements outside of functions.and it also reduces the length of the program


What is functions in c?

A function is a small set of instructions designed to operate on its given input (aka parameters or arguments) and perform some action or return some output. Generally in programming a commonly used strategy is to take a large program and break it into smaller chunks, which are turned into functions. So say that you are writing a large program and constantly have to see which of two numbers is larger, you could write a function: int larger(int a, int b) { if(a > b) return a; else return b; } Now in your program, you can simply say: int x = larger(number1, number2);


How pointers reduce the length of a program?

They don't.


Definition of instruction length it has something to do with computer?

what is instruction length and what is instruction format and what is program length and what is the difference among them


What is the typical length of a thesis for a master's degree program?

The typical length of a thesis for a master's degree program is around 50-100 pages, but this can vary depending on the specific requirements of the program and the field of study.


How does HBO determine its programming schedule?

HBO determines its programming by the length of the program and rating of the program.


What is the typical length of a PhD program in the USA?

The typical length of a PhD program in the USA is around 5 to 7 years, depending on the field of study and individual progress.


What is the typical length of a thesis paper for a master's degree program?

A typical thesis paper for a master's degree program is usually around 50 to 100 pages in length.


Write a program in pascal that calculates the area of a circle?

{Area s the area of cube} {Length is the length of one side of the cube} program AreaofCube; var Area,Length:real; begin write('Enter the length of cube: '); readln(Length); Area:=6*(Length*Length); writeln('The area of cube is ', Area, ' cm^2.'); end.