gpt4 book ai didi

在同一文件中调用另一个函数的函数

转载 作者:行者123 更新时间:2023-11-30 20:21:55 24 4
gpt4 key购买 nike

我有一个错误按摩,但我不明白问题是什么。我正在拼命寻找问题。我尝试创建一个库函数,并将其中一个函数包含在同一文件中的另一个函数上。这可能吗?如果是,请解释一下。

  #include "head.h"

void fungsiCetak()
{
int i,n;
system("cls");
system("color 1f");
FILE*nip,*nama,*golongan,*anak,*kk,*birth;
nip=fopen("nip.txt","a");
nama=fopen("nama.txt","a");
anak=fopen("jum_anak.txt","a");
kk=fopen("jum_kk.txt","a");
birth=fopen("birth.txt","a");
golongan=fopen("golongan.txt","a");
//////////////////////////////////////////////////////////////////
fflush(stdin);
printf("Berapa data yang ingin di inputkan ? ");
scanf("%d",&n);
i=1;
do{
fflush(stdin);
printf(" Masukan NIP : ");
gets(pegawai.nip);
fprintf(nip,"%s\n",pegawai.nip);
printf("Masukan nama Pegawai : ");
gets(pegawai.nama);
fprintf(nama,"%s\n",pegawai.nama);
printf("Masukan golongan : ");
scanf("%d",&pegawai.gol);
fprintf(golongan,"%d\n",pegawai.gol);
printf("Jumlah anak : ");
scanf("%d",&pegawai.jum_anak);
fprintf(anak,"%d\n",pegawai.jum_anak);
printf("Jumlah anggota keluarga : ");
scanf("%d",&pegawai.jum_kk);
fprintf(kk,"%d\n",pegawai.jum_kk);
printf("Tanggal lahir (dd-mm-yyyy) : ");
scanf("%d-%d-%d",&pegawai.birth.hari,
&pegawai.birth.bulan,
&pegawai.birth.tahun);
fprintf(birth,"%d-%d-%d\n",pegawai.birth.hari,
pegawai.birth.bulan,
pegawai.birth.tahun);
printf("\n");
i++;
} while(i<=n);

fclose(nip);
fclose(nama);
fclose(golongan);
fclose(anak);
fclose(kk);
fclose(birth);
}
void fungsiBaca()
{
system("cls");
int count=0;
int nip2,nip1[20],anak1[20],kk1[20];
int gol[20];
char birth1[30][30];
char bufer[100],buffer1[100];
char nama1[30][30];

struct pegawai;
FILE*nip,*nama,*golongan,*anak,*kk,*birth;
nama=fopen("nama.txt","r");
i=0;
while(fgets(bufer,sizeof bufer,nama)!=NULL)
{
strcpy(nama1[i],bufer);
i++;
}
a=0;
golongan=fopen("golongan.txt","r");
while(a<=i)
{
fscanf(golongan,"%d",&gol[a]);
a++;
}
nip=fopen("nip.txt","r");
a=0;
while(a<i)
{
fscanf(nip,"%d",&nip1[a]);
a++;
}
anak=fopen("jum_anak.txt","r");
a=0;
while(a<i)
{
fscanf(anak,"%d",&anak1[a]);
a++;
}
kk=fopen("jum_kk.txt","r");
a=0;
while(a<i)
{
fscanf(kk,"%d",&kk1[a]);
a++;
}
birth=fopen("birth.txt","r");
a=0;
while(fgets(buffer1,sizeof buffer1,birth)!=NULL)
{
strcpy(birth1[a],buffer1);
a++;
}
search :
fflush(stdin);
printf("----------------------------------------\n");
printf("masukan NIP : ");
scanf("%d",&nip2);
printf("----------------------------------------\n");
for(a=0; a<=i; a++)
{
if(nip1[a]==nip2){
printf("Nama pegawai : %s",nama1[a]);
printf("Golongan : %d\n",gol[a]);
printf("Jumlah anak : %d\n",anak1[a]);
printf("Jumlah KK : %d\n",kk1[a]);
printf("Tanggal Lahir : %s\n",birth1[a]);
count=1;
}
}
if (count==0)
{
printf("Maaf data tidak ditemukan!\n");
}
fflush(stdin);
printf("Ingin mencari data kembali ? [y/n]");
scanf("%c",&kembali);
if (kembali=='y')
{
system("cls");
goto search;
}
fclose(nip);
fclose(nama);
fclose(golongan);
fclose(kk);
fclose(anak);
fclose(birth);
}
void fungsiGaji ()
{
int gol,absen;
float tunj_makan,tunj_anak,tunj_kes,total,gajih_pokok;
fungsiBaca();
//////////////////////////////////////////////////Kondisi gajih pokok
if (gol[a]==1)
{
gajih_pokok=GOl1;
} else if (gol[a]==2)
{
gajih_pokok=GOL2;
} else if (gol[a]==3)
{
gajih_pokok=GOl3;
} else
{
gajih_pokok=GOL4;
}
printf("Gajih pokok : %.2f",gajih_pokok);
/////////////////////////////////////////////// kondisi tunjangan

}

错误信息是 i我使用 CodeBlocks 来创建程序

最佳答案

问题出在这里:

int gol,absen; <--- gol is integer
...
if (gol[a]==1) <---- gol[a] ?

关于在同一文件中调用另一个函数的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41158499/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com