c语言输出数组 字符数组 输出

C语言。输入一个字符串按反方向存放,并将其输出。怎样编写这个程序?_百度知道
C语言。输入一个字符串按反方向存放,并将其输出。怎样编写这个程序?
刚学C于语言,答案不会很复杂的、
提问者采纳
int main(void){/输入字符串x=strlen(nArr);char nArr[100];#include&#include&;/%c&=0;i--){printf(&&#47.h&//找出字符串长度for(i=x;可以自己定义数组的大小;/&#47,nArr).h>scanf(&quot,nArr[i]);%s&/倒序输出字符串}return 0;i&gt
其他类似问题
为您推荐:
c语言的相关知识
其他3条回答
将输入的字符串放进数组里,然后将数组内的内容从后到前依次输出!
突发奇想,用堆栈和管道似乎解决这个问题更简单有效,而且不用考虑字符串长度:
#include &fcntl.h&
#include &io.h&
#include &memory.h&
#include &stdio.h&
#include &string.h&
#define szSTR 256
/*递归方式逆序存储字符串,将逆序内容写入fw底层流文件*/
void rev(char * src, int fw)
if (!src || fw & 1)
if (!*src) /*如果字符串结束则返回*/
rev(src + 1, fw); /*递归到下一个字符地址*/
write(fw, src, 1); /*递归返回后将字符写入管道*/
/*反向函数,输入src,输出des*/
void strv(char * src, char * des)
int p[2] = {0, 0}; /*创建一对管道用于读写*/
_pipe(p, _O_BINARY, szSTR);
rev(src, p[1]); /*将输入内容反方向写入管道*/
scanf(&s&,a);n=strlen(a);for(i=n-1;i&=0;i--)printf(&%c&,a[i]);
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁关于C语言中的字符串数组输入输出控制符的若干问题_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
关于C语言中的字符串数组输入输出控制符的若干问题
C​语​言​ ​ ​,​输​入​输​出
阅读已结束,如果下载本文需要使用
想免费下载本文?
把文档贴到Blog、BBS或个人站等:
普通尺寸(450*500pix)
较大尺寸(630*500pix)
你可能喜欢当前位置: &
C语言怎么不用数组和指针实现字符串的反向输出
城市:拉萨
城市:拉萨
可以用链表,一看你的问题,不用数组和指针我也不会,我也是搜的……#include &stdio.h&#include &malloc.h&#define LEN sizeof(struct string)struct string{
struct string *
struct string *};struct string *creat(void){
struct string *
struct string *p1,*p2;
p1=p2=(struct string*)malloc(LEN);
scanf("%c",&p1-&ch);
head=NULL;
while(p1-&ch!='\n')
if(n==1)head=p1;
p2-&next=p1;
p1-&before=p2;
p1=(struct string*)malloc(LEN);
scanf("%c",&p1-&ch);
p2-&next=NULL;}struct string *input(void){
struct string *
struct string *p1,*p2;
p1=(struct string*)malloc(LEN);
scanf("%c",&p1-&ch);
p2=head=p1;
while(p1-&ch!='\n')
p1=(struct string*)malloc(LEN);
scanf("%c",&p1-&ch);
p2-&next=p1;
p1-&before=p2;
p2-&next=NULL;}struct string *danxiang(void)//反向输入函数{
struct string *
struct string *p1,*p2;
p1=(struct string*)malloc(LEN);
scanf("%c",&p1-&ch);
p2-&before=NULL;
while(p1-&ch!='\n')
p1=(struct string*)malloc(LEN);
scanf("%c",&p1-&ch);
p1-&before=p2;
p1-&next=NULL;}print2(struct string *end)//反向输出函数{
struct string*
printf("\n反向输出结果为:\n");
for(p=p!=NULL;p=p-&before)
printf("%c",p-&ch);
putchar('\n');}
//双向链表输出函数print(struct string *head){
struct string *p;
while(p-&next!=NULL)
printf("\n反向输出结果为:\n");
while(p!=head)
printf("%c",p-&ch);
printf("%c\n",head-&ch);
putchar('\n');
}shuchu1(void){
struct string *
number=creat();
print(number);}shuchu2(void){
struct string *
number=input();
print(number);}shuchu3(void){
struct string *
number=danxiang();
print2(number);}void main(){
printf("请输入字符串:\n");
//shuchu1();
shuchu2();
//shuchu3();
putchar('\n');}
//程序说明/*
creat和input函数是双向链表的输入函数;shuchu1\shuchu2\shuchu3是三个控制输出的函数,每次运行程序只能用一个shuchu函数来实现,
(也就是说可以用creat和print、input和print、danxiang和print2分别搭配使用,运行时在main函数中需注释掉两个shuchu才能实现输出)
剩下的两个函数分别是控制输出的。
城市:拉萨
看题意是应该用栈来处理,不过指针不用主要是指不用数组及字符指针来处理反向输出,c语言要是真离开了指针,可就寸部难行了(就像没了内存一样),下面程序确实只用一个变量,完全用栈来处理输出,并避开了字符指针,已调试通过。#include "stdio.h"#include "conio.h"// 栈大小#define MAX_STACK
100// 栈顶,只有这一个变量static unsigned long stack_top=0;// 栈操作,当栈溢出时,自动丢弃最早压入的数据// c!=0 push c, c==0 pop c, return
cchar stack(char c){// 回车退出if(c=='\r')if(c) // push{memmove((void*)(stack_top+1),(void*)stack_top,MAX_STACK-1);memset((void*)(stack_top),c,1);}else
// pop{memmove((void*)&c,(void*)stack_top,1);memmove((void*)stack_top,(void*)(stack_top+1),MAX_STACK-1);}}int main(int argc, char* argv[]){// 初始化栈stack_top = (unsigned long) alloca(MAX_STACK);memset((void*)(stack_top),0,MAX_STACK);printf("input string and CR end\n");//压栈while(stack( putch( getch()) )!='\r');printf("\n");// 反向输出,出栈while( putch(stack( 0 ))& 0);printf("\n");return 0;}
匿名回答:C语言中字符数组输出“烫烫烫烫烫烫烫”,如何解决_好搜问答
|注册&您有新任务,
C语言中字符数组输出“烫烫烫烫烫烫烫”,如何解决
被浏览389次
采纳率:50%
有烫烫烫烫烫烫烫
说明你的字符数组其内容不明
一般需如下解决:扩大数组范围
或初始化数组 用微信扫描二维码分享至好友和朋友圈分享到:
下面是答答童鞋给您的小建议,您看靠谱吗?初来乍到,弄错了您不要生气哦(*^__^*)答答小贴士
等您帮助的附近的朋友换一换
大家都在搜好搜APP下载好搜摸字APP 随时随地随心搜索 用好搜, 特顺手!
第9天生活就像海洋,只有意志坚强的人才能达到生命的彼岸。知道了

我要回帖

更多关于 c语言输出数组 的文章

 

随机推荐