填空题
在给定程序中,函数fun的功能是:在形参ss所指字符串数组中查找与形参t所指字符串相同的串,找到后返回该串在字符串数组中的位置(下标值),未找到则返回-1,ss所指字符串数组中共有N个内容不同的字符串,且串长小于N。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构。
文件BLANK1.C内容如下:
#include<stdio.h>
#include<string.h>
#define N 5
#define M 8
int fun(char(*ss)[M],char *t)
int i:
/**********found**********/
for(i=0;i< (1) ;i++)
/**********found**********/
if(stremp(ss[i],t)==0)return (2) ;
return -1;
void main( )
char ch[N][M]="f","while","switch","int","for",t[M];
int n,i;
printf("\nThe original stringin\n");
for(i=0;i<N;i++)puts(ch[i]);
printf("\n");
printf("\nEnter a string for search: ");
gets(t);
n=fun(eh,t);
/**********found**********/
if(n== (3) )printf("\nDon’t found!\n");
else printf("\nThe position is%d.\n",n);
【参考答案】
i
热门
试题
问答题
学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,它的功能是:函数返回指定学号的学生数据,指定的学号在主函数中输入。若没有找到指定学号,在结构体变量中给学号置空串,给成绩置-1,作为函数值返回(用于字符串比较的函数是strcmp)。 注意:部分源程序在文件PROG1.C中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 文件PROG1.C内容如下: #include<stdio.h> #include<string.h> #define N 16 typedef struet char num[10]; int s ; STREC ; STREC fun( STREC * a, char * b ) void main( ) t STREC s[N] = GA005 ,85, GA003 ,76 , GA002 ,69 , GA004 ,85, GA001 ,91, GA007 ,72, GA008 ,64, GA006 ,87 , GA015 ,85, GA013 ,91, GA012 ,64, GA014 ,91 , GA011 ,77, GA017 ,64, GA018 ,64, GA016 ,72 ; STREC h ; char m[10]; int i ; printf( The original data: n ) ; for(i=0; i<N; i++) if(i%4==0) printf( n ); printf( %s %3d ,s[i].num,s[i].s); printf( n nEnter the number: ) ; gets ( m ) ; h=fun( s,m ); prinff( The data : ) ; prinff( n%s %4d n ,h. num,h.s);