#include<stdio.h>
#include<string.h>
#define ALL 10
struct name
{
char na[10];
}namelist[ALL];
void show() //show all the students' name
{
int i;
for(i=0;i<ALL;i++)
{
printf("The ");
printf("%d",i+1);
printf(" student's name is:");
printf("%s/n",namelist[i].na);
}
}
int write()
{
FILE *fp;
int i;
fp=fopen("md.txt","w");
for(i=0;i<ALL;i++)
{
fprintf(fp,"The ");
fprintf(fp,"%d",i+1);
fprintf(fp," student's name is:");
fprintf(fp,"%s/n",namelist[i].na);
}
fclose(fp);
printf("Save the file success./n");
}
int main()
{
int i;
char ch[10];
char maker[]="lianhao";
printf("please input 10 students' name/n");
for(i=0;i<ALL;i++)
{
printf("The ");
printf("%d",i+1);
printf(" student's name is:");
gets(namelist[i].na);
if(strcmp(namelist[i].na,maker)==0)
{
strcpy(ch,namelist[0].na);
strcpy(namelist[0].na,namelist[i].na);
strcpy(namelist[i].na,ch);
}
}
show();
write();
return 0;
}
#include<string.h>
#define ALL 10
struct name
{
char na[10];
}namelist[ALL];
void show() //show all the students' name
{
int i;
for(i=0;i<ALL;i++)
{
printf("The ");
printf("%d",i+1);
printf(" student's name is:");
printf("%s/n",namelist[i].na);
}
}
int write()
{
FILE *fp;
int i;
fp=fopen("md.txt","w");
for(i=0;i<ALL;i++)
{
fprintf(fp,"The ");
fprintf(fp,"%d",i+1);
fprintf(fp," student's name is:");
fprintf(fp,"%s/n",namelist[i].na);
}
fclose(fp);
printf("Save the file success./n");
}
int main()
{
int i;
char ch[10];
char maker[]="lianhao";
printf("please input 10 students' name/n");
for(i=0;i<ALL;i++)
{
printf("The ");
printf("%d",i+1);
printf(" student's name is:");
gets(namelist[i].na);
if(strcmp(namelist[i].na,maker)==0)
{
strcpy(ch,namelist[0].na);
strcpy(namelist[0].na,namelist[i].na);
strcpy(namelist[i].na,ch);
}
}
show();
write();
return 0;
}