Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Define a structure for a line string and implement a function that takes a line string and returns the overall length of the line string.

What I have tried:

stringLength(struct string *s)
{
return s->length;


}
Posted
Updated 27-Oct-18 7:19am
Comments
MadMyche 27-Oct-18 11:00am    
And what happens when you try this? Wrong or no value? An error?
...Help us help you, as we can't read your mind or see your screen...
Rick York 27-Oct-18 13:30pm    
"Define a structure for a line string" - you didn't do this part.

You must get information about your
C++
struct string
because it may have a member which has the length, but read carefully it could also be the max size. Than the the solution of Dirk with the string data.

I guess you need to learn a lot to improve your coding skills. Take time and learn or you will fail. Google for some tutorial or read your school documents an practise .

Good luck
 
Share this answer
 
I am assuming your string is null terminated '\0' - so you could do it like this in ANSI C. I have not actually tested the code but I am pretty sure it should work like this - an alternative solution is also to increase s and i and check for the end of the string with this expression *s != '\0';

C
stringLength(struct string *s)
{
  int i=0;

  while(s[i] != '\0') i++;

  return i;
} 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900