len2.c
来自「linux下的C语言开发」· C语言 代码 · 共 33 行
C
33 行
/*-*//******************************************************** * Answer to question 8.1. * * * * For full details, see the book. * ********************************************************//*+*/#include <stdio.h>int length(char string[]){ int index; /* index into the string */ /* * Loop until we reach the end of string character */ for (index = 0; string[index] != '\0'; ++index) continue; /* do nothing */ return (index);}int main(){ char line[100]; /* Input line from user */ while (1) { printf("Enter line:"); fgets(line, sizeof(line), stdin); printf("Length (including newline) is: %d\n", length(line)); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?