字符串输入的拓展
Posted 新起点1
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字符串输入的拓展相关的知识,希望对你有一定的参考价值。
#include <stdio.h> #include <stdlib.h> #include <string.h> const size_t BUFFER_LEN =128; const size_t NUM_P =3; char buffer[128]; char *pS[3]={NULL}; char *pbuffer =buffer ; int i; int main() { printf("\n You can enter up to %u message each up to %u ge ",NUM_P,BUFFER_LEN-1); for (i=0;i<NUM_P;i++) { pbuffer=buffer ; printf("\n Enter %s message ",i>0?"another":"a"); while ((pbuffer-buffer<BUFFER_LEN-1)&&(*(pbuffer++)=getchar())!=‘\n‘); if((pbuffer-buffer)<2) break; if((pbuffer-buffer)==BUFFER_LEN&&*(pbuffer-1)!=‘\n‘) { printf("String too long "); i--; continue; } *(pbuffer-1)=‘\0‘; pS[i]=(char*)malloc(pbuffer-buffer); if(pS[i]==NULL) { printf("\n OUT of memory "); return 1; } strcpy(pS[i],buffer); } printf("\n In reverse order .the strings you entered are :\n"); while (--i >= 0) { printf("\n%s",pS[i]); free(pS[i]); pS[i]=NULL; } system("pause"); return 0; }
以上是关于字符串输入的拓展的主要内容,如果未能解决你的问题,请参考以下文章
java缓冲字符字节输入输出流:java.io.BufferedReaderjava.io.BufferedWriterjava.io.BufferedInputStreamjava.io.(代码片段