lastchar.c
来自「The art and science of c_source code!」· C语言 代码 · 共 43 行
C
43 行
/* * File: lastchar.c * ---------------- * This file defines the function LastChar, which returns the * last character in a string. */#include <stdio.h>#include "genlib.h"#include "strlib.h"#include "simpio.h"/* Function prototypes */char LastChar(string str);/* Main program */main(){ string str; printf("This program displays the last character in a string.\n"); printf("Enter a string: "); str = GetLine(); printf("The last character is '%c'\n", LastChar(str));}/* * Function: LastChar * Usage: ch = LastChar(str); * -------------------------- * This function returns the last character in the string str. * If LastChar is called on the empty string, an error condition * is reported because the IthChar function performs range * checking on the index. */char LastChar(string str){ return (IthChar(str, StringLength(str) - 1));}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?