c语言编程,指针类型。各位高手你们快来救救我吧!

来源:百度知道 编辑:UC知道 时间:2024/04/28 06:52:21
问题是:从少数如文件读入十个数据,用指针实现逆序排列,结果放入输出文件中.. 。题目看懂了吗?
高手们谢谢拉·!

程序代表我的心呵呵:以下是我给你写的.调试已经通过.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define max 516

void main()
{
FILE * fp;
char str[max]={0};
char *p,*p1,td;
char c;
if((fp=fopen("read.txt","r"))==NULL)
{
printf("can not open file");
exit(0);
}
c=fgetc(fp);
int i=0;
while((c!=EOF)&&(i<10))
{
str[i]=c;
c=fgetc(fp);
i++;
}
printf("\n取得的十个数据为:%s\n",str);
p=str;
p1=&str[i-1];
int star=1;
int fini=i;
while(star<fini)
{
td=*p;
*p=*p1;
*p1=td;
p++;
p1--;
star++;
fini--;
}
printf("\n逆转后的结果为:%s\n",str);
fclose(fp);
if((fp=fopen("write.txt","w"))==NULL)
{
printf("open file faile\n");
exit(0)