⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reverse.c

📁 reverse your input string
💻 C
字号:
/* reverse.c: reverse a string   bob wilson     09/18/02     */#include <stdio.h>#define MAXLINE 1000/* function prototypes */static void reverse(char line []);int strlen(char line[]);int main (){	int i, c;	char line[MAXLINE];	i = 0;	while ((c = getchar()) != EOF) {		line[i] = c;		++i;		if (c == '\n') {			line[i] = '\0';    /* add a zero to end string */			reverse(line);			printf("%s", line);			i = 0;		}	}	return 0;}/* pseudo code for reverse function	find length of the string to reverse	for each character from the beginning of the string to half way	     copy the character here to a holding variable	     copy the character the same distance from end to here	     copy the holding variable to the same distance from endend of pseudo code*/static void reverse (char line[]){	int len, i;	char c;	len = strlen(line) - 1;             /* array index = len - 1  */	for (i=0; i<=len/2; ++i) {          /* go halfway through the line */		c = line[i];                /* save a character from line */		line[i] = line[len-i];      /* overwrite that character */		line[len-i] = c;            /* save reversed character */	}}int strlen (char line[]){	int i;	i=0;	while (line[i])		++i;	return i;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -