69,373
社区成员
发帖
与我相关
我的任务
分享
#include <string.h>
#include <stdio.h>
#define N 81
fun (char *s)
{int i,num=strlen(s);
char t;
for(i=0;i<num;i++)
{
t=s[i];
s[i]=s[num-i-1];
s[num-i-1]=t;
}
}
NONO()
{/* 请在此函数内打开文件,输入测试数据,调用 fun 函数,输出数据,关闭文件。 */
int i ;
char a[N] ;
FILE *rf, *wf ;
rf = fopen("in.dat","r");
wf = fopen("out.dat","w");
for(i = 0 ; i < 10 ; i++) {
fscanf(rf, "%s", a);
fun(a);
fprintf(wf, "%s\n", a);
}
fclose(rf);
fclose(wf);
}
main()
{char a[N];
printf ("Enter a string : "); gets (a);
printf ("The original string is : "); puts(a);
fun (a);
printf("\n");
printf ("The string after modified : ");
puts (a);
NONO();
}
fun (char *s)
{
char b[N];
int i=0, j;
memset(b, 0, N);
for(j=strlen(s)-1; j>=0; j--)b[i++]=s[j];
strcpy(s, b);
}
#include <string.h>
#include <stdio.h>
#define N 81
void fun (char **s)
{
int i,num=strlen(*s);
char t;
for(i=0;i<num/2;i++)//---------你的等于没有变化
{
t=(*s)[i];
(*s)[i]=(*s)[num-i-1];
(*s)[num-i-1]=t;
}
(*s)[num] = '\0';
}
void NONO()
{/* 请在此函数内打开文件,输入测试数据,调用 fun 函数,输出数据,关闭文件。 */
int i ;
char *a = new char [N];
FILE *rf, *wf ;
rf = fopen("in.dat","w+");//--文件打开格式错了
wf = fopen("out.dat","r+");
for(i = 0 ; i < 1 ; i++) {
fscanf(rf, "%s", a);
fun(&a);
fprintf(wf, "%s\n", a);
}
fclose(rf);
fclose(wf);
}
main()
{
char *a = new char[N];
printf ("Enter a string : ");
gets (a);
printf ("The original string is : ");
puts(a);
fun (&a);
printf("\n");
printf ("The string after modified : ");
puts (a);
NONO();
}
#include <string.h>
#include <stdio.h>
#define N 81
void fun (char **s)
{
int i,num=strlen(*s);
char t;
for(i=0;i<num/2;i++)
{
t=(*s)[i];
(*s)[i]=(*s)[num-i-1];
(*s)[num-i-1]=t;
}
(*s)[num] = '\0';
}
void NONO()
{/* 请在此函数内打开文件,输入测试数据,调用 fun 函数,输出数据,关闭文件。 */
int i ;
char *a = new char [N];
FILE *rf, *wf ;
rf = fopen("in.dat","w+");
wf = fopen("out.dat","r+");
for(i = 0 ; i < 1 ; i++) {
fscanf(rf, "%s", a);
fun(&a);
fprintf(wf, "%s\n", a);
}
fclose(rf);
fclose(wf);
}
main()
{
char *a = new char[N];
printf ("Enter a string : ");
gets (a);
printf ("The original string is : ");
puts(a);
fun (&a);
printf("\n");
printf ("The string after modified : ");
puts (a);
NONO();
}