等级考试上机题目(上课用)(2)
时间:2026-01-17
时间:2026-01-17
{FILE *fp; int i;
STYPE s[10];
if((fp=fopen("myfile5.dat","rb"))==NULL)
{printf("Fail !!\n"); exit(0);}
printf("\nRead file and output to screen :\n");
printf("\n num name tel\n");
for(i=0; i<N; i++)
{fread(&s[i],sizeof(STYPE),1, fp);
printf("%6d %s %s\n",s[i].num, s[i].name,s[i].tel);
}
fclose(fp);
}
2.改错题
#include <stdio.h>
#include <string.h>
void fun (char *s, char *t)
{int i, sl;
sl = strlen(s);
/************found************/
for(i=0; i<=s1; i ++)
t[i] = s[i];
for (i=0; i<sl; i++)
t[sl+i] = s[sl-i-1];
/************found************/
t[sl] = '\0';
}
main()
{char s[100], t[100];
printf("\nPlease enter string s:"); scanf("%s", s);
fun(s, t);
printf("The result is: %s\n", t);
}
2
下一篇:LED电子屏招标公告