更多"函数readDat( )的功能是从文件in52.dat中读取20行数据"的相关试题:
[多项选择]函数readDat( )是从文件IN.DAT中读取20行数据存放到字符串数组XX中(每行字符串长度均小于80)。请编制函数jsSort( ),其功能是:以行为单位对字符串按下面给定的条件进行排序,排序后的结果仍按行重新存入字符串数组XX中,最后调用函数writeDat( )把结果XX输出到文件OUT.DAT中。条件:从字符串中间一分为二,左边部分按字符的ASCⅡ值降序排序,右边部分按字符的ASCⅡ值升序排序。如果原字符串长度为奇数,则最中间的字符不参加排序,字符仍放在原位置上。
例如,位置 0 1 2 3 4 5 6 7 8
源字符串 a b c d h g f e
1 2 3 4 9 8 7 6 5
则处理后字符串d c b a e f g h
4 3 2 1 9 5 6 7 8
注意:部分源程序存在文件PROG1.C文件中。请勿改动数据文件IN.DAT中的任何数据、主函数main( )、读函数readDat( )和写函数writeDat( )的内容。
[试题程序]
#include
#include
char XX[20][80];
void readDat( );
void writeDat( );
void jsSort( )
void main( )
readDat( );
jsSort( );
writeDat( );
void readDat( )
FILE *in;
int i=0;
char *p;
in=fopen("in.dat","r");
while(i<20&&fgets(xx[i],80,in)!=NULL)
p=strchr(xx[i],’/n’);
if(p) *P=0;
i++;
fclose(in);
void writeDat( )
FILE *out;
int i;
out=fop
[多项选择]函数readDat( )是从文件in71.dat中读取20行数据存放到字符串数组xx中(每行字符串长度均小于80)。请编制函数JsSon( ),其功能是:以行为单位对字符串按下面给定的条件进行排序,排序后的结果仍按行重新存入字符串数组xx中。最后调用函数writeDat( )把结果xx输出到文件out71.dat中。
条件:从字符串中间一分为二,左边部分按字符的ASCⅡ值降序排序,右边部分按字符的ASCⅡ值升序排序。如果原字符串长度为奇数,则最中间的字符不参加排序,字符仍放在原位置上。
例如: 位置0 1 2 3 4 5 6 7 8
源字符串a b c d h g f e
1 2 3 4 9 8 7 6 5
处理后的字符串d c b a e f g h
4 3 2 1 9 5 6 7 8
注意:部分源程序已给出。
请勿改动主函数main( )、读函数readDat( )和写函数writeDatO的内容。
试题程序:
#include<stdio.h>
#include<string.h>
#include<conio.h>
char xx[20][80];
void isSoYt( )
void main( )
readDat( );
isSort( );
writeDat( );
readDat ( )
FILE *in;
int i=0;
char *p;
in=fopen ("in71.dat", "r");
while (i<20 && fgets(xx[i],80,in)!=NULL)
p=strchr (xx [i] , ’/n’ );
if (p)
*p=0;
i++;
fclose (in);
writeDat ( )
FILE
[多项选择]读函数readDat( )的功能是从文件IN25.DAT中读取20行数据存放到字符串数组xx中(每行字符串长度均小于80)。请编制函数jsSort( ),该函数的功能是:以行为单位对字符串按下面给定的条件进行排序,排序后的结果仍按行重新存入字符串数组xx中,最后调用写函数writeDat( )把结果xx输出到文件OUT25.DAT中。
条件:从字符串中间一分为二,左边部分按字符的ASCII值升序排序,排序后,左边部分与右边部分按例子所示进行交换。如果原字符串长度为奇数,则最中间的字符不参加处理,字符仍放在原位置上。
例如: 位置 0 1 2 3 4 5 6 7 8
源字符串 d c b a h g f e
4 3 2 1 9 8 7 6
处理后字符串 h g f e a b c d
9 8 7 6 1 2 3 4
注意:部分源程序已给出。
请勿改动主函数main( )、读函数readDat( )和写函数writeDat( )的内容。
试题程序:
#include 〈stdio.h>
#include 〈string.h>
#include 〈conio.h>
char xx[20] [80]; void jsSort( )
main ( )
readDat ( );
jsSort ( );
writeDat ( );
readDat ( )
FILE *in;
int i=0;
char *p;
in = fopen("IN25.DAT", "r");
while(i〈20 && fgets(xx[i], 80, in) != NULL)
p = strchr(xx[i], ’/n’);
if(p) *p = 0;
i++;
fclose(in);
writeDat ( )
FILE *out
[简答题]给定程序MODI1.C中函数fun的功能是: 比较两个字符串,将长的那个字符串的首地址作为函数值返回。
请改正函数fun中指定部位的错误, 使它能得出正确的结果。
注意: 不要改动main函数, 不得增行或删行, 也不得更改程序的结构!
给定源程序:
#include
char fun(char *s, char *t)
{ int sl=0,tl=0; char *ss, *tt;
ss=s; tt=t;
while(*ss)
{ sl++;
(*ss)++;
}
while(*tt)
{ tl++;
(*tt)++;
}
if(tl>sl) return t;
else return s;
}
main( )
{ char a[80],b[80],*p,*q; int i;
printf("/nEnter a string : "); gets(a);
printf("/nEnter a string again : "); gets(b);
printf("/nThe longer is :/n/n/"%s/"/n",fun(a,b));
}
[填空题]
以下程序中函数 huiwen 的功能是检查一个字符串是否是回文,当字符串是回文时,函数返回字符串 yes!,否则函数返回字符串 no!,并在主函数中输出,所谓 回文即正向与反向的拼写都一样,例如:adgda。请填空。
#include
char *huiwen(char *str)
{ char *p1,*p2; int i,t=0;
p1=str;p2==_______ ;
for(i=0;i<=strlen(str)/2;i++)
if(*p1++!=*p2--){t=1;break;}
if(=_______ ) return("yes!");
}
main( )
else return("no!");
{ char str[50];
printf("Input:"); scanf("%s",str);
printf("%s/n",=_______ );
}
[填空题]以下程序中函数huiwen的功能是检查一个字符串是否是回文,当字符串是回文时,函数返回字符串yes!,否则函数返回字符串no!,并在主函数中输出,所谓回文即正向与反向的拼写都一样,例如:adgda。请填空。
#include<string.h>
char*huiwen (char*str)
{char*p1,*p2;int i,t=0;
p1=str;p2=【 】。
for(i=0;i<strlen(str)/2;i++)
if(*p1++!=*p2-){t=1;break;}
if(【 】)return("yes"!);
else return("no!");
}
main( )
{char str[50];
printf("Input:");scanf("%s",str);
printf("%s/n",【 】);
}
[填空题]str是一个由数字和字母字符组成的字符串,由变量num传入字符串长度。请补充函数fun( ),该函数的功能是:把字符串str中的数字字符转换成数字并存放到整型数组bb中,函数返回数组bb的长度。
例如:str=“Bcdl23e456hui890”,结果为:123456890。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#define N 80
int bb[N];
int fun(char s[ ],int bb[ ],int num)
{
int i,n=0;
for(i=0;i<num;i++)
{
if( 【1】 )
{
bb[n]= 【2】 ;
n++;
}
}
return 【3】 ;
}
main( )
{
char str[N];
int num=0,n,i;
printf("Enter a string:/n");
gets(str);
while(str[num])
num++;
n=fun(str,bb,num);
printf("/nbb=");
for(i=0;i<n;i++)
printf("%d",bb[i]);
}