| 發表文章 | 發起投票 |
又係C programming
整左個function 用黎remove data file 入面嘅 record, 但係print 左句野出黎之後就停左,有冇巴打可以幫下我
#include <stdio.h>
#include <stdlib.h>
struct staff
{
char name[50];
int age, salary;
};
void change()
{
int i, j;
char x;
char inname[50];
struct staff record[100];
FILE * a = fopen("staff.txt", "r");
for (i = 0 ; i < 100 ; i++)
{
fscanf(a,"%s%d%d",record);
}
fclose(a);
printf("Which record do you want to remove?");
gets(inname);
while (record.name == inname)
record = record[i+1];
FILE * b = fopen("staff.txt", "w+");
fprintf(a,"%s%d%d",record);
fclose(a);
printf("Do you want to remove another staff record? (Y/N)");
scanf("%c",&x);
fflush(stdin);
if (toupper(x) == 'Y')
{
change();
}
else if (toupper(x) == 'N')
{
main();
}
do
{
printf("Invalid value, please input again.");
printf("Do you want to remove another staff record? (Y/N)");
scanf("%c",&x);
fflush(stdin);
if (toupper(x) == 'Y')
{
change();
}
else if (toupper(x) == 'N')
{
main();
}
}
while (toupper(x) != 'Y' || toupper(x) != 'N');
}
int main()
{
change();
return 0;
}
#include <stdio.h>
#include <stdlib.h>
struct staff
{
char name[50];
int age, salary;
};
void change()
{
int i, j;
char x;
char inname[50];
struct staff record[100];
FILE * a = fopen("staff.txt", "r");
for (i = 0 ; i < 100 ; i++)
{
fscanf(a,"%s%d%d",record);
}
fclose(a);
printf("Which record do you want to remove?");
gets(inname);
while (record.name == inname)
record = record[i+1];
FILE * b = fopen("staff.txt", "w+");
fprintf(a,"%s%d%d",record);
fclose(a);
printf("Do you want to remove another staff record? (Y/N)");
scanf("%c",&x);
fflush(stdin);
if (toupper(x) == 'Y')
{
change();
}
else if (toupper(x) == 'N')
{
main();
}
do
{
printf("Invalid value, please input again.");
printf("Do you want to remove another staff record? (Y/N)");
scanf("%c",&x);
fflush(stdin);
if (toupper(x) == 'Y')
{
change();
}
else if (toupper(x) == 'N')
{
main();
}
}
while (toupper(x) != 'Y' || toupper(x) != 'N');
}
int main()
{
change();
return 0;
}
本貼文共有 0 個回覆
此貼文已鎖,將不接受回覆
| 發表文章 | 發起投票 |