实现一个函数,该函数接受一个行字符串并返回行字符串的总长度。 [英] Implement a function that takes a line string and returns the overall length of the line string.

查看:88
本文介绍了实现一个函数,该函数接受一个行字符串并返回行字符串的总长度。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

定义一个行字符串的结构并实现一个函数,该函数接受一个行字符串并返回行字符串的总长度。



我是什么尝试过:



stringLength(struct string * s)

{

返回s- >长度;





}

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;


}

推荐答案

您必须获取信息关于你的
You must get information about your
struct string

因为它可能有一个有长度的成员,但仔细阅读它也可能是最大尺寸。比Dirk的解决方案与字符串数据。



我想你需要学到很多东西来提高你的编码技巧。花时间学习,否则你会失败。谷歌的一些教程或阅读你的学校文件练习



祝你好运

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


我是假设你的字符串是空终止'\ 0' - 所以你可以在ANSI C中这样做。我没有实际测试过代码,但我很确定它应该像这样工作 - 另一种解决方案也是增加 s i 并使用此表达式检查字符串的结尾 * s!='\\ \\ 0';



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';

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

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

  return i;
} 


这篇关于实现一个函数,该函数接受一个行字符串并返回行字符串的总长度。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆