私は、ファイルにのみ、特定の値を編集したい、 ファイル内の特定の値を編集するにはどうすればよいですか?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int month[3]={0,0,0};
int month1;
printf("\n1.December");
printf("\n2.November");
printf("\nEnter month:");
scanf("%d",&month1);
if(month1 == 2)
{
printf("\nthis is November");
month[1]=3*5;
printf("\ntotal for this month is :%d",month[1]);
}
else if (month1 == 1)
{
printf("\nthis is December");
month[2]=2*5;
printf("\ntotal for this month is :%d\n\n\n",month[2]);
}
FILE *mo;
if((mo = fopen ("month.txt", "w")) == NULL)
{
printf ("File unable to open");
} // end if
else
{
fprintf(mo,"Transaction for December is %d ",month[2]);
fprintf(mo,"\nTransaction for November is %d ",month[1]);
}
return 0;
system("pause");
}
のは、私は一度このプログラムを実行し、その後、プログラムはファイルでこの値を格納するとしましょう。 と12月のどのファイルmonth.txt内部
トランザクションの下に11月10 取引では、私は再びこのプログラムを実行した後、0
が作るためにどのように、10の値は自動的に0に関連付けるを変更しませんその値を更新します。 そして、それは(私は3時間このプログラムを実行した後) は、最初のiは、1秒を選択し、第三、私は2を選択し、ファイルmonth.txt でこのように見えるように、12月の
取引は11月の10 取引では30
です