Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help! How can I get my code to access the accounts.txt file and display the output below? My code: struct Person{ char name[31]; int
Please help! How can I get my code to access the accounts.txt file and display the output below?
My code:
struct Person{ char name[31]; int birthYr; double income; char country[31];};struct UserLogin{ char username[11]; char password[9];};struct Account{ int acctNo; char acctType; struct Person personInfo; struct UserLogin loginInfo;};int i, j;FILE* fp = NULL;struct Account accts[15] = { 0 };fp = fopen("accounts.txt", "r");if (fp != NULL){ while (fscanf(fp, "%d~%c~%s~%d~%lf~%s~%s~%s", accts.acctNo, accts.acctType, accts.personInfo.name, accts.personInfo.birthYr, accts.personInfo.income, accts.personInfo.country, accts.loginInfo.username, accts.loginInfo.password) != EOF) //returns errorfor (i = 0; i
accounts.txt
30001~C~Silly Sally~1990~150000.10~CANADA50599~A~Fred Flintstone~1972~2250400.22~AFRICA~agent1~yAb1#a@B30004~C~Betty Boop~1978~250800.74~INDIA50008~A~Will Smith~1952~2350600.82~U.S.A.~agentJ~TT*&21tt30020~C~Shrimpy Shrimp~2000~350500.35~KOREA34000~A~Xyla Yates~1991~61907.58~GREECE~Cherokee~EJ13dq&*50007~C~Chaney Kinney~1963~22288.09~SLOVENIA30014~A~Hanae Horn~1999~35403.36~SPAIN~Keiko~RM52rg&*40021~C~Kane Lancaster~1951~77711.60~PORTUGAL35035~C~Honorato Banks~1999~83024.91~HONDURAS42042~C~Dexter Martin~1932~40187.20~GUAM35049~C~Buck Odom~1990~60494.16~LESOTHO44056~C~Craig Mcknight~1961~91914.61~BAHAMAS34063~C~Jeffrey Gills~1989~27746.17~SRI LANKA50070~A~Wylie Pollard~1990~61384.65~ALBANIA~Lara~EO42vs&*35077~A~May Ramos~1980~96023.83~CANADA~Althea~OL10yi&*34084~C~Lacota Miller~1984~75247.37~LUXEMBOURG33091~C~Lael Dudley~1943~60250.27~SWITZERLAND52098~C~Guinevere Preston~1934~23735.99~VENEZUELA35105~C~Emery Hyde~1971~79236.39~SPAIN34112~A~Holly Knowles~1947~43713.36~MOROCCO~Shelby~PJ99uk&*63119~A~Breanna Holden~1946~53111.60~SAUDI ARABIA~Naomi~CO15dj&*64126~A~Owen Harris~1936~67631.11~MOROCCO~Barry~XX25rj&*35133~C~Keegan Bryan~1985~67600.35~CAMEROON32140~A~Merritt Alford~1940~00916.66~CURAAO~Cameron~CI36vj&*33147~C~Gloria Byrd~1942~99811.57~KUWAIT64154~C~Baker Mckenzie~1986~82695.63~KIRIBATI35161~A~Stacy Compton~1950~02547.36~SLOVENIA~Giacomo~FJ17js&*64028~A~Julian Solis~1943~78813.86~WESTERN SAHARA~Calista~YG01ts&*33168~C~Clementine Woods~1938~82613.70~SOUTH SUDAN
Expected output:
Acct# Acct. Type Full Name Birth Income Country Login Password 30001 CUSTOMER Silly Sally 1990 150000.10 CANADA 50599 AGENT Fred Flintstone 1972 2250400. 22 AFRICA agentl y*b*#*@* 30004 CUSTOMER Betty Boop 1978 250800. 74 INDIA 50008 AGENT Will Smith 1952 2350600. 82 U.S.A. agent] T+4#2+ +* 30020 CUSTOMER Shrimpy Shrimp 2090 350500.35 KOREA 34000 AGENT Xyla Yates 1991 61907.58 GREECE Cherokee E*1*d* & + 50007 CUSTOMER Chaney Kinney 1963 22288.09 SLOVENIA 30014 AGENT Hanae Horn 1999 35403. 36 SPAIN Keiko R*5+r* &* 40021 CUSTOMER Kane Lancaster 1951 77711.60 PORTUGAL 35035 CUSTOMER Honorato Banks 1999 83024.91 HONDURAS 42042 CUSTOMER Dexter Martin 1932 40187.20 GUAM 35049 CUSTOMER Buck Odom 1990 60494.16 LESOTHO 44056 CUSTOMER Craig Mcknight 1961 91914. 61 BAHAMAS 34063 CUSTOMER Jeffrey Gills 1989 27746. 17 SRI LANKA 50070 AGENT Wylie Pollard 1990 61384. 65 ALBANIA Lara E*4*v+&+Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started