main()括号里面不用填的。完整的程序如下
#include <stdio.h>
#include<string.h>
void main ()
{ char a[20]= "abcXYZ", c
int i, j
j= strlen(a)-1
for (i=0 j>ii++,j--)
{
c=*(a+i)
*(a+i)=*(a+j)
*(a+j)=c }
puts(a)
}
结果是将 a[20]= "abcXYZ"逆序输出,输出结果:ZYXcba
有什么不懂的还可以再问我
//先解释一下文件合并的意思//假设文件A中是cba,文件B中是zyx,则合并后(按字母顺序)文件C中是abcxyz
//你给的程序中有三处错误。两处fputs函数错误,一处逻辑错误,以下程序已修正
#include "stdio.h"
main()
{ FILE *fp
int i,j,n,ni
char c[160],t,ch
if((fp=fopen("A","w"))==NULL)
{
printf("cannot open file\n")
exit(0)
}
printf("please input a string\n")
gets(c)
fputs(c,fp)//去掉双引号
fclose(fp)
//以上从键盘上输入一个字符串,然后将其写入A文件中
if((fp=fopen("B","w"))==NULL)
{
printf("cannot open file\n")
exit(0)
}
printf("please input a string\n")
gets(c)
fputs(c,fp)//去掉双引号
fclose(fp)
//以上从键盘上输入一个字符串,然后将其写入文件B中
if((fp=fopen("A","r"))==NULL)
{printf("file A cannot be opened\n")
exit(0)}
printf("\n A contents are :\n")
for(i=0(ch=fgetc(fp))!=EOFi++)
{c[i]=ch
putchar(c[i])
}
fclose(fp)
//以上把文件A中的字符串存放到数组c中,并输出文件A中的内容
ni=i
if((fp=fopen("B","r"))==NULL)
{printf("file B cannot be opened\n")
exit(0)}
printf("\n B contents are :\n")
for(i=ni(ch=fgetc(fp))!=EOFi++)//此处i的初试值应该是ni,因为要接着已有的字符串往下存放
{c[i]=ch
putchar(c[i])
}
fclose(fp)
//以上把文件B中的字符串存放到数组c中(接着已有的字符串往下继续存放),并输出文件B中的内容
n=i
for(i=0i<ni++)
for(j=i+1j<nj++)
if(c[i]>c[j])
{t=c[i]c[i]=c[j]c[j]=t}
printf("\n C file is:\n")
fp=fopen("C","w")
for(i=0i<ni++)
{ putc(c[i],fp)
putchar(c[i])
}
fclose(fp)
}
//以上将数组c中的字符排序,然后存放到文件C中并在屏幕上显示数组c中的内容