Hello ive written a program but it does not want to read from a referenced text file.
i wonder if anyone can tell me what the problem is? below is the source code and after that is the text file.
ok here is the text file. It is titled info.txt.
111 234
002 892
003 463
004 673
005 932
i wonder if anyone can tell me what the problem is? below is the source code and after that is the text file.
Code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int choice, count;
FILE *inputfile = NULL;
char option,pin,transaction;
int deposit, withdraw,fpin,fbal,temp;
option='0';
int acctid[20], acctbal[20];
choice = 3;
while(choice != 2)
{
system ("cls");
printf("WELCOME TO SAMUEL'S BANK\n");
printf("------------------------------\n\n");
printf("Main Menu\n");
printf("------------------------------\n");
printf("1)Enter Pin #\n");
printf("2)Exit\n");
printf("------------------------------\n\n");
scanf("%c", &option);
if (option =='2')
{
break;
}
if (option == '1')
{
system ("cls");
printf("Pin Number Verification\n");
printf("------------------------------\n\n");
printf("Please enter your pin number: ");
scanf("%s", &pin);
}
inputfile =fopen("info.txt","r");
if (inputfile == NULL)
{
printf("Unable to open input file\n");
return 1;
}
count = 0;
while ( fscanf(inputfile, "%d" "%d", &fpin, &fbal ) == 2 )
{
count++;
acctid[count] = fpin;
acctbal[count] = fbal;
if (acctid[count] == pin)
{
temp = count;
system ("cls");
printf("Transactions\n");
printf("------------------------------\n");
printf("1)Deposit\n2)Withdraw\n3)Statement\n4)Exit\n");
printf("------------------------------\n");
scanf("%s",&transaction);
if (transaction =='1')
{
system ("cls");
printf("Deposit\n");
printf("------------------------------\n\n");
printf("Please enter the amount of money you would like to deposit: ");
scanf("%d", &deposit);
}
if (transaction =='2')
{
system ("cls");
printf("Withdraw\n");
printf("------------------------------\n\n");
printf("Please enter the amount of money you would like to withdraw: ");
scanf("%d", &withdraw);
}
if (transaction=='3')
{
system ("cls");
printf("Statement\n");
printf("------------------------------\n\n");
}
fclose(inputfile);
}
}
}
return 0;
}
ok here is the text file. It is titled info.txt.
111 234
002 892
003 463
004 673
005 932
Comment