| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 421 人关注过本帖
标题:[求助]为什么没有输出呢?
只看楼主 加入收藏
wordess
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-10-27
收藏
 问题点数:0 回复次数:4 
[求助]为什么没有输出呢?

#include "string.h"
#include "conio.h"
#include<stdio.h>
#include<math.h>
#define N 81

fun(char *p)
{
int i,n,t;
n=strlen(p);
for(i=0;p+i<p+n-1-i;i++)
{
t=*(p+i);
*(p+i)=*(p+n-i);
*(p+n-i)=t;
}

}
void main()
{
char a[N];
char *p1;
p1=a;

printf("input the score:\n");
gets(a);
printf("read the score:\n");
puts(a);
p1=a;
fun(a);
printf("\n");
printf("read the score:\n");
printf("%s",*p1);
}

我是新手,请教各位高手,谁能帮我解释一下,为什么没有输出?应该怎么改??我是在VC和WIN-TC运行的..

搜索更多相关主题的帖子: 输出 
2006-11-22 15:38
unicorn
Rank: 4
等 级:贵宾
威 望:14
帖 子:1066
专家分:0
注 册:2005-10-25
收藏
得分:0 

你的交换函数写的太冗杂了,直接用指针交换就方便多了
运行一下下面的

*#include<stdio.h>
#define N 81

void fun(char *p)
{
char *p1,*p2,ch;
p1=p2=p;
while(*p2!='\0')
p2++;
p2--;

while(p1<p2)
{ ch=*p2;*p2=*p1;*p1=ch;
p1++;p2--;
}
}
void main()
{
char a[N];
char *p;
p=a;
printf(\"input the score:\n\");
gets(a);
printf(\"read the score:\n\");
puts(a);
fun(a);
printf(\"\n\");
printf(\"read the score:\n\");
printf(\"%s\",p);//输出的是字符首地址,不是*p


unicorn-h.spaces. ◇◆ sava-scratch.spaces.  noh enol ! pue pu!w hw u! shemle aq ll!m noh 
2006-11-22 15:59
smartwind
Rank: 1
等 级:新手上路
威 望:1
帖 子:277
专家分:0
注 册:2006-11-13
收藏
得分:0 

#include \"string.h\"
#include \"conio.h\"
#include<stdio.h>
#include<math.h>
#define N 81

fun(char *p)
{
int i,n;
char t;
n=strlen(p);
for(i=0;p+i<p+n-2-i;i++)
{
t=*(p+i);
*(p+i)=*(p+n-i-1);
*(p+n-i-1)=t;
}

}
void main()
{
char a[N];
char *p1;
p1=a;

printf(\"input the score:\n\");
gets(a);
printf(\"read the score:\n\");
puts(a);
fun(a);
printf(\"\n\");
printf(\"read the score:\n\");
printf(\"%s\n\",p1);
}


2006-11-22 16:08
财鸟
Rank: 1
等 级:新手上路
帖 子:132
专家分:0
注 册:2006-11-2
收藏
得分:0 
n=strlen(p);
是不是有问题!!!!!!!!!!!!!!

你是不是要把执行FUN()函数后的字符串函数进行一下扫描输出!!!!!!!!!
搞不懂你想输出什么!!!!!!!!!!!!
但你至少要对printf("%s",*p1);中的P1缚你需要输出的地址吧!!!!!!!!!!


我真的不知道你想做什么!!!!!!!!!!!!1
fun(*P1);看看吧!!!!!!!!!!!1
2006-11-22 16:10
wordess
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-10-27
收藏
得分:0 
谢谢你们的指点
2006-11-22 16:33
快速回复:[求助]为什么没有输出呢?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013717 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved