bufdemo程序

    xiaoxiao2023-10-09  139

    这个程序是要我们输入一个字符串,放入长度为4的数组中,然后由运行结果可知,如果输入的字符不超过4个,就会依次输出字符串中的字符,如果字符串长度超过4,那么字符串中多出的字符会自动存入栈中,然后再输出 #include <stdio.h> #include <stdlib.h> /* Implementation of library function gets() */ char *gets(char *dest) { int c = getchar(); char *p = dest; while (c != EOF && c != '\n') { *p++ = c; c = getchar(); } *p = '\0'; return dest; } /* Read input line and write it back */ void echo() { char buf[4]; /* Way too small! */ gets(buf); puts(buf); } void call_echo() { echo(); } int main() { printf("Type a string:"); call_echo(); return 0; }

    最新回复(0)