怎样在一个循环中,输入一组字符串,其中有的字符串可能是空字符串,怎么输入呢?

来源:百度知道 编辑:UC知道 时间:2024/06/15 20:30:05

1. 用标准函数
#include "stdio.h"
#include "stdlib.h"

void main()
{
char bufs[256];
gets(bufs)
pts(bufs);

}

2. 自己写函数,以回车作为字符串结束符
#include "stdio.h"
#include "stdlib.h"
#include "conio.h"

int mygetsw(char * buf,int len)
{ int i=0;
while(1){
c=getche();
if(c!=13){ i++, *buf++=c;}
else {*buf = '\0'; return i;}
}

void main()
{
char bufs[256];
mygetsw(bufs,256);
pts(bufs);

}