Please help me with this code. when i tried to run it, it doesn't continue to this part
"printf("\n\n Money: ");" but when i tried to change the data type of money to integer it does continue, but i need a float data type. please help, thank you.

#include<stdio.h>
#include<conio.h>

void main()
{
 clrscr();

 FILE *rec;

 rec= fopen("rec_log.txt", "w");

 struct reco
     {
      char acc[6];
      char pin[5];
      int money;
     }log[3];

 for(int i=1;i<4;i++)
    {
     printf("\n\n Enter Account: ");
     scanf("%s",log[i].acc);
     fprintf(rec,"\n\n Account no.%d : %s",i, log[i].acc);
     printf("\n\n Enter Pin: ");
     scanf("%s",log[i].pin);
     fprintf(rec,"\n\n Pin no.%d : %s",i, log[i].pin);
     printf("\n\n Money: ");
     scanf("%f",log[i].money);
     fprintf(rec,"\n\n Money: %f",log[i].money);
    }

    fclose(rec);

 getch();
}//main

Several problems.

  1. In struct reco, the money field is an int, not a float.
  2. You need to return an int from main() - at least for current compilers and systems.

Oh thank you for that, i tried to chang int -> float , still, the problem is there.

why are you using an array of reco objects? The array is not needed, just re-use the same instance of reco.

The loop on line 19 is wrong -- arrays are always numbered starting with 0, not 1. In your program valid array numbers are 0, 1, and 2. There is no array element number 3, and that may be why your program crashes.

i'm using array because i need to store 3 different data

It can be done just as easily like this

#include<stdio.h>
#include<conio.h>

struct reco
{
  char acc[6];
  char pin[5];
  float money;
}log;

int main()
{
 clrscr();

 FILE *rec;

 rec= fopen("rec_log.txt", "w");


 for(int i=1;i<4;i++)
    {
     printf("\n\n Enter Account: ");
     scanf("%s",log.acc);
     fprintf(rec,"\n\n Account no.%d : %s",i, log.acc);
     printf("\n\n Enter Pin: ");
     scanf("%s",log.pin);
     fprintf(rec,"\n\n Pin no.%d : %s",i, log.pin);
     printf("\n\n Money: ");
     scanf("%f",log.money);
     fprintf(rec,"\n\n Money: %f",log.money);
    }

    fclose(rec);

 getch();
}//main

thank you very much sir!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.