c语言while问题

时间:2015.10.23 发布人:圣光与_你同在

c语言while问题

已解决问题

谷歌圣光与_你同在用户在2015.10.23提交了关于“郎咸平c语言while问题”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-11-14T21:52:18。

输入字符,当遇到“#”时结束输入,将“#”之前的字符输出

希望大家能够帮助她。

详细问题描述及疑问:

输入字符,当遇到“#”时结束输入,将“#”之前的字符输出

期待您的答案,你就是当代的活雷锋,太感谢了 !
希望以下的回答,能够帮助你。

第1个回答

用户名:真飞飞侠  

//#include<stdio.h>
//#include<malloc.h>
/田帮编候创裂/#include<stdlib.h>
//#defineMaxsize50
来自//typedefcharelemtype;
//typedefstruct
//{
//elemtypedata[Maxsize];
//intlength;
//}Sqlist;
//
//voidcreatelist(Sqlist*&L,elemtypea[],intn问答)
//{
//inti;
//L=(Sqlist*)malloc(sizeof(Sqlist));
//for(i必察独=0;i<n;i++)
//L->data[i]=a[i];
//L->length=n;
//}
//
//voidinitlist(Sqlist*&L)
//{
//L=(Sqlist*)malloc(停乙sizeof(Sqlist));
//L->len能力gth=0;
//}
//
端被开觉答承失//voiddestor率器苦呀弦感击功吃ylist(Sq器数料另相制未次list*&L)//L)貌似是不是半角英文输入法,改掉
//{
//free(L);
//}
//
//boollistempty(Sqlist*L)
//{
//return(L->length=围望=0);
//}
//
//intlistlength(Sqlist*L)
//{
//return(L->length);
//}
//
//voiddi坚splist(Sqlist*L)
//{
//inti必杂划继另影环;
//for(i=0;名教同端搞抗备营应甲i<L->length;i++)
//printf("%d",L->data[i球几家兰球敌]);
//printf("\n");//这儿是中文输入法,改掉
//}
//
//boolgetelem(Sqlist*L,inti,elemtype&e)
//{
重终前//if(i<1||府胶深气十计齐到服i>L->length)//这儿要将iL改为i
总础切报是斤武许布钟弱//returnfalse落督害七六虽笑践袁菜赵;
//e=L->data[i能般天亚烧事掉积做城问-1];
//ret测变策真觉urntrue;//将ture改为true
//}
//
//intlocatelem(Sqlist*L,elemtypee)
//{
//inti=0;
//while(i>=L->length&&L->data[i]!=e)
//i++;
//if(i>=L->length)
//return0;
//else
//returni+1;
//}
//
//boollistinsert(Sqlist*&L,inti,elemtypee)
//{
//intj;
//if(i<1||i<L->length+1)
//returnfalse;
//i--;
//for(j=L->length;j>i;j--)
//L->data[j]=L->data[j-1];
//L->data[i]=e;
//L->length++;
//returntrue;//将ture改为true
//}
//
//boollistdelete(Sqlist*&L,intj,elemtype&e)
//{
////intj;//这儿的逻辑比较混乱,比如说i变量没有定义啊,上面的形参已经有j了为什么下面还要定义一个j呢
//inti=j;//新添加的
//if(i<1||i<L->length)
//returnfalse;
//i--;
//e=L->data[i];//新的最后一个值
//
////进行迁移,将要删除的值覆盖掉
//for(j=i+1;j<L->length-1;j++)//这儿j要等于i+1,因为之前你已经减过了,指向新的最后一个值位置
////或者你什么也不做,因为上面你都是对i进行操作的,没有改变j的值,而j本来就是指向要删除的元素的
//L->data[j]=L->data[j+1];
//L->length--;
//returntrue;//将ture改为true
//}
//
//#include<stdio.h>
//#include<memory>
//#include<iostream>
//
//usingnamespacestd;
//
//voidmain()
//{
//floata,b,sum;
//scanf("%f,%f",&a,&b);
//sum=a=b;
//printf("sum=%d\n",sum);
//
//std::unique_ptr<int>ip=std::m**e_unique<int>(10);
//int**m=10;
//int*p=&**m;
//int*q=(int*)(&p);//q就是指向p的地址
//
//printf("%d\n",**((int**)q));//要想获取真正的值的话,就要将他转换为真正的目标指针
//
//getchar();
//
//boola=false;
//boolb=false;
//boolc=true;
//
//if(b||c&&a)
//{
//cout<<"ok"<<endl;
//}
//getchar();
//}
//
//#include<stdio.h>
//
//计算平均分
//double**erage_score(doublescores[],intcount)
//{
//doublesum=0.0;
//for(inti=0;i<count;++i)
//{
//sum+=scores[i];
//}
//returnsum/count;
//}
//
//统计分数在平均分以上的人数
//intstatistic_**ve_**erage(doublescores[],intcount,double**erage)
//{
//int**ve_count=0;
//for(inti=0;i<count;++i)
//{
//if(scores[i]>**erage)
//{
//**ve_count++;
//}
//}
//return**ve_count;
//}
//
//intmain(intargc,char**ar**)
//{
//doublescores[]={80.5,79.4,98,22.2};//假设他是班级所有学生的分数
//double**erage=**erage_score(scores,sizeof(scores)/sizeof(double));
//int**ve_person=statistic_**ve_**erage(scores,sizeof(scores)/sizeof(double),**erage);
//
//printf("The**eragescoreofthisclassis%f\n",**erage);
//printf("Thecountofpersionwhosescoreismorethan**erageis%d\n",**ve_person);
//
//getchar();
//}
//
//指针实现
//#include<stdio.h>
//
//voidcalculate_and_statistic(constdouble*scores,intcount,double***erage,int***ve_**erage)
//{
//doublesum=0.0;
//***erage=0.0;
//***ve_**erage=0;
//
//if(scores==0||count<=0||**erage==**LL||**ve_**erage==**LL)
//{
//return;
//}
//
//for(inti=0;i<count;++i)
//{
//sum+=*(scores+i);
//}
//***erage=sum/count;
//
//for(intj=0;j<count;++j)
//{
//if(*(scores+j)>***erage)
//{
//(***ve_**erage)++;
//}
//}
//}
//
//intmain(intargc,char**ar**)
//{
//
//doublescores[]={80.5,79.4,98,22.2};//假设他是班级所有学生的分数
//int**ve_person=0;
//double**erage=0.0;
//
//calculate_and_statistic(scores,sizeof(scores)/sizeof(double),&**erage,&**ve_person);
//printf("The**eragescoreofthisclassis%f\n",**erage);
//printf("Thecountofpersionwhosescoreismorethan**erageis%d\n",**ve_person);
//
//getchar();
//charbuffer[225];
//gets_s(buffer);
//
//char*str;
//gets_s(str,100);
//
//return0;
//}
//
//#include<iostream>
//#include<string>
//intmain()
//{
//usingnamespacestd;
//charname[]="Corney";
////charn;
//stringn;//这儿定义一个字符串,将上面的字符定义注释掉
//cout<<"Whoami.\nPleaseenteraname:";//加一个分隔符,这样输入的字符串就比较清晰
//do
//{
//cin>>n;
//if(n=="Corney")//直接==就行,推荐使用下面那行写法
////if(n==name)
//cout<<"right\n";//推荐使用下面哪种写法
////cout<<"right"<<endl;//他不但会在末尾添加\n,而且会将cout的**缓冲区中的内容输出到屏幕上
//else
//cout<<"Tryagain.\n";
//}while(n!=name);
//return0;
//}
//
//#include<stdio.h>
//#include<stdlib.h>
//doubleround(doublex)//推荐把返回值double改为int,这样下面的那儿就不用改动了,如果不变的,那么下面printf那儿进行按我写的那样改
//{
//
//
//intn=(int)(x+0.5);
//returnn;
//}
//
//intmain()
//{
//
//printf("%2f→%f\n",1.6,round(1.6));//把后面的%d改为%f,因为你写的round函数返回值为double类型,所以使用%f进行输出
//getchar();
//return0;
//
//int**answer=(int**)malloc(sizeof(int*)*scope);
//
//int**answer_cursor=answer;//新添加的
//for(inti=0;i<scope;i++)
////*answer=(int*)malloc(sizeof(int)*scope);//因为你是对*answer进行设置,没有移动到下一个位置,而你下面
////访问无效地址(没有使用有效地址进行初始化)肯定会访问冲突了
//{
//*answer_cursor=(int*)malloc(sizeof(int)*scope);
//++answer_cursor;
//}
////******************************************************************************
//for(inti=0;i<scope;i++)
//for(intj=0;j<scope;j++)
//{
//intin=rand()%10;
//if(in>=4&&in<=7)
//answer[i][j]=1;//*(*(answer+i)+j)=1;
//
//else
//answer[i][j]=0;//*(*(answer+i)+j)=0;
//}
//
//}
//
//
//#define_CRT_**CURE_NO_WARNINGS
//#include<stdio.h>
//
//intadd(inta,intb)
//{
//returna+b;
//}
//
//
//
//intsub(inta,intb)
//{
//returna-b;
//}
//
//
//
//intmul(inta,intb)
//{
//returna*b;
//}
//
//
//
//doublediv(inta,intb)
//{
//returna*1.0/b;
//}
//
//
//
//intmain(intargc,char**ar**)
//{
//inta,b;
//
//printf("请输入两个整数(以逗号分隔):");
//scanf("%d,%d",&a,&b);
//
//printf("a+b=%d\n",add(a,b));
//printf("a-b=%d\n",sub(a,b));
//printf("a*b=%d\n",mul(a,b));
//
//
//if(b!=0)
//printf("a/b=%f\n",div(a,b));
//
//#if_MSC_VER>1200
//printf("Pressanykeytoexit");
//getchar();
//getchar();
//#endif
//}
//
//

#define_CRT_**CURE_NO_WARNINGS
#include<stdio.h>


intmain(intargc,char**ar**)
{
constintkBufferSize=1024;
charbuf[kBufferSize]={0};//最多输入1024个字符,可以自己设置
intindex=0;

do
{
scanf("%c",&buf[index]);
if('#'==buf[index])
{
buf[index]='\0';
bre**;
}
++index;
}while(true);

printf("%s\n",buf);

#if_MSC_VER>1200
printf("Pressanykeytoexit\n");
getchar();
getchar();
#endif

return0;

}