Data File p1artstxt Assignment Use an array of linked list t
Data File: “p1arts”.txt”
Assignment:
Use an array of linked list to process the data file to produce the output similar to the following output file : Name the output file “p3artists_arts.txt”.
Each artist will occupy one row of the array.
Try to design the structure of the first node. In addition to “artistID” and “next” fields, what else should it contain
Artist ID
Artist Name
Art ID
Art Title
Appraised Value
50
Morgan
1001
Red Rock Mountain
18000
1028
Tired Cowboy
4700
1054
Snake Charmer
4500
1068
Moonlight
9750
1069
Renaissance
5500
1113
Shadow House
5500
1114
Storytelling at the Campfire
18000
52
Novarre
1002
Offerings
10000
p1arts.txt:
1001 Red Rock Mountain 50 18000
1002 Offerings 52 10000
1003 Spring Flowers 12 2400
1004 Seeking Shelter 64 52000
1005 The Hang 18 8000
1006 House Remembered 32 700
1007 Homage to the Ancestors 82 1200
1008 End of the Path 26 1900
1009 Amen 28 3000
1010 Untitled (land with adobe) 71 800
1011 Eve 19 975
1012 Man on Horseback 74 8000
1013 Superstitions 3 78000
1014 Plenty 45 500
1015 Punch 46 10000
1016 Untitled 65 6000
1017 Brittlecone 6 1300
1018 Mountain Scene 8 2500
1019 The White Heart 61 9300
1020 Untitled (Man holding coat) 73 3000
1021 Bead Wall 3 14000
1022 The Cowboy 69 4200
1023 Shooting the Rapids 47 1300
1024 Spirit and Nature 48 592
1025 Profile of a Woman 68 625
1026 Untitled (couple) 66 4000
1027 Mountain Climber 47 4700
1028 Tired Cowboy 50 4700
1029 Horseshoe Falls 31 15000
1030 Ash Bench 28 13000
1031 Inside/Out 34 3500
1032 Rising Sun 42 2000
1033 Untitled (Woman abstract) 77 2500
1034 Beaver Pole Jumble 3 28000
1035 Nature/Nurture 47 1300
1036 Blackhawk 5 25500
1037 Floating World 21 2350
1038 Spring Flowers 1 800
1039 Treachery 14 20000
1040 Night on the Praire 47 1300
1041 Night Version 29 3800
1042 Coffee on the Trail 2 7544
1043 Creosote Bushes 28 18000
1044 Mexican Fiesta 43 14000
1045 Leaf Patterns 38 2100
1046 Immediate Gratification 33 1500
1047 Medicine Man 44 2500
1048 Comfy Chair 57 800
1049 Buttercup with Red Lip 7 400
1050 Cattle Ranch 1 10000
1051 Night Version 36 7000
1052 American Rodeo 16 3500
1053 Blue Eyed Indian 6 40000
1054 Snake Charmer 50 4500
1055 Starlit Evening 9 9500
1056 Cavalry Is Coming 6 1900
1057 Untitled 66 4500
1058 The Gathering 60 250
1059 Dwelling 17 16000
1060 Story Sticks 42 650
1061 Untitled Mural 78 3520
1062 Cowboy and Saddle 41 18000
1063 Asleep in the Garden 3 110000
1064 Spirit Columns 51 7000
1065 Moonlite 47 1300
1066 Untitled (still life) 76 19500
1067 Owl in Flight 49 7000
1068 Moonlight 50 9750
1069 Renaissance 50 5500
1070 Beginnings 4 27500
1071 Ride the Rapids 79 300
1072 Funnel 24 4500
1073 Dancing in the Light 15 4000
1074 Storm on the Rise 55 8000
1075 Western Boots and Spurs 6 6000
1076 Ride the Bronco 79 1500
1077 Bull Riding 6 5200
1078 Chuckwagon 28 32000
1079 Carrying the Mail 62 8000
1080 The Dust Behind 59 18000
1081 Coming Under Fire 13 650
1082 Spring Flowers 29 20000
1083 Untitled 64 2500
1084 Crossing the Platt River 23 2200
1085 Traces 63 20000
1086 Untitled (desert landscape) 67 18000
1087 Three Woman 81 20000
1088 Lessons 37 3700
1089 Life Lessons 53 4125
1090 Off the Grid 11 8000
1091 Stone Palette 54 11500
1092 Dressing Up 47 1300
1093 Antelopes 62 12500
1094 Life Is Sweet 39 25000
1095 The Spirit 61 20000
1096 Ceremonial Sticks 10 15000
1097 Untitled (Sea) 75 2800
1098 Sweet Project 56 592
1099 Watch That Rattler 20 900
1100 Hungry Cowboys 38 750
1101 The Red Door 58 10000
1102 Crying Hats 14 10000
1103 Trail End 1 8000
1104 Untitled 70 1800
1105 Meteor Show 80 10000
1106 Horse Corral 40 12500
1107 Striking It Rich 35 1750
1108 Untitled Mural 77 400
1109 Friends 22 16000
1110 Three Sisters 62 6500
1111 Untitled (man and crucifix) 72 3200
1112 Dark Canyon 27 8000
1113 Shadow House 50 5500
1114 Storytelling at the Campfire 50 18000
1115 Starry Night 25 8500
1116 Apache Warrior 30 23000
p1artists.txt:
1 Acconci
2 Ames
3 Aserty
4 Baron
5 Battenberg
6 Bindner
7 Blain
8 Blum
9 Budd
10 Cardenas
11 Carpenter
12 Chico
13 Colvin
14 Cox
15 Cridler
16 Curtis
17 Dawson
18 DiGrigoro
19 Dill
20 Edwards
21 Fleming
22 Fratt
23 Garber
24 Garin
25 Giama
26 Gilhooly
27 Gonzales
28 Guys
29 Hamend
30 Higgins
31 Hofmann
32 Ibe
33 Indiana
34 Ingraham
35 Irvin
36 Kerrihard
37 Kollasch
38 Kritz
39 Lerman
40 Long
41 Lowney
42 Lundquist
43 Lutes
44 Maglich
45 McGraw
46 McIver
47 Meglech
48 Metz
49 Miller
50 Mogan
51 Motherwell
52 Novarre
53 Odiezma
54 Ortega
55 Parker
56 Penn
57 Pierobon
58 Prinzen
59 Quiroz
60 Rath
61 Reed
62 Rissman
63 Rogers
64 Roman
65 Schenck
66 Scherzel
67 Scholder
68 Senior
69 Shenal
70 Statom
71 Swartz
72 Tidwell
73 Turrell
74 Udinotti
75 Van Coller
76 Waid
77 Werner
78 Wittner
79 Wright
80 Xie
81 Yasami
82 Zischke
| Artist ID | Artist Name | Art ID | Art Title | Appraised Value |
| 50 | Morgan | 1001 | Red Rock Mountain | 18000 |
| 1028 | Tired Cowboy | 4700 | ||
| 1054 | Snake Charmer | 4500 | ||
| 1068 | Moonlight | 9750 | ||
| 1069 | Renaissance | 5500 | ||
| 1113 | Shadow House | 5500 | ||
| 1114 | Storytelling at the Campfire | 18000 | ||
| 52 | Novarre | 1002 | Offerings | 10000 |
Solution
As per my understanding you have to create an array of linklist. So We have created two structures. One for artist Id and name and second for art with respect to each artist id. Please find the source code and output file.
Source Code:
#include<stdio.h>
#include<stdlib.h>
typedef struct array_linklist // sturcture of art list in the array
{
int art_id;
char title[30];
int value;
struct array_linklist *next;
}list;
struct artist // sturcture of array
{
int artist_id;
char name[20];
list *art;
};
void main()
{
int i,j,n,len;
char str[50],fstr[50];
list *temp,*new;
FILE *f1,*f2,*fo;
f1= fopen(\"p1arts.txt\",\"r\");
f2= fopen(\"p1artists.txt\",\"r\");
fo= fopen(\"p3artists_arts.txt\",\"w\");
struct artist arr[100]={NULL};
i=1;
while(fscanf(f2,\"%d\",&arr[i].artist_id)!=EOF)
{
fscanf(f2,\"%s\",arr[i].name);
i++;
}
while(fscanf(f1,\"%d\",&j)!=EOF)
{
fscanf(f1,\"%s\",str);
strcpy(fstr,\"\");
while(str[0]<48 || str[0]>57)
{
strcat(fstr,str);
strcat(fstr,\" \");
fscanf(f1,\"%s\",str);
}
len=strlen(str);
if(len==2)
n=(str[0]-48)*10+(str[1]-48);
else
n=(str[0]-48);
if(arr[n].art == NULL)
{
arr[n].art = (list *)malloc(sizeof(list));
fscanf(f1,\"%d\",&(arr[n].art->value));
arr[n].art->art_id = j;
strcpy(arr[n].art->title,fstr);
arr[n].art->next = NULL;
}
else
{
new = (list *)malloc(sizeof(list));
fscanf(f1,\"%d\",&(new->value));
new->art_id = j;
strcpy(new->title,fstr);
new->next = NULL;
temp = arr[n].art;
while(temp->next != NULL)
temp = temp->next;
temp->next = new;
}
}
for(j=1;j<i;j++)
{
fprintf(fo,\"%d\\t\",arr[j].artist_id);
fprintf(fo,\"%s\\t\\t\",arr[j].name);
temp = arr[j].art;
while(temp != NULL)
{
fprintf(fo,\"%d\\t\",temp->art_id);
fprintf(fo,\"%s\\t\",temp->title);
fprintf(fo,\"%d\\t\ \",temp->value);
if(temp->next!=NULL)
fprintf(fo,\"\\t\\t\\t\");
temp = temp->next;
}
fprintf(fo,\"\ \");
}
}
Output: p3artists_arts.txt
1 Acconci 1038 Spring Flowers 800
1050 Cattle Ranch 10000
1103 Trail End 8000
2 Ames 1042 Coffee on the Trail 7544
3 Aserty 1013 Superstitions 78000
1021 Bead Wall 14000
1034 Beaver Pole Jumble 28000
1063 Asleep in the Garden 110000
4 Baron 1070 Beginnings 27500
5 Battenberg 1036 Blackhawk 25500
6 Bindner 1017 Brittlecone 1300
1053 Blue Eyed Indian 40000
1056 Cavalry Is Coming 1900
1075 Western Boots and Spurs 6000
1077 Bull Riding 5200
7 Blain 1049 Buttercup with Red Lip 400
8 Blum 1018 Mountain Scene 2500
9 Budd 1055 Starlit Evening 9500
10 Cardenas 1096 Ceremonial Sticks 15000
11 Carpenter 1090 Off the Grid 8000
12 Chico 1003 Spring Flowers 2400
13 Colvin 1081 Coming Under Fire 650
14 Cox 1039 Treachery 20000
1102 Crying Hats 10000
15 Cridler 1073 Dancing in the Light 4000
16 Curtis 1052 American Rodeo 3500
17 Dawson 1059 Dwelling 16000
18 DiGrigoro 1005 The Hang 8000
19 Dill 1011 Eve 975
20 Edwards 1099 Watch That Rattler 900
21 Fleming 1037 Floating World 2350
22 Fratt 1109 Friends 16000
23 Garber 1084 Crossing the Platt River 2200
24 Garin 1072 Funnel 4500
25 Giama 1115 Starry Night 8500
26 Gilhooly 1008 End of the Path 1900
27 Gonzales 1112 Dark Canyon 8000
28 Guys 1009 Amen 3000
1030 Ash Bench 13000
1043 Creosote Bushes 18000
1078 Chuckwagon 32000
29 Hamend 1041 Night Version 3800
1082 Spring Flowers 20000
30 Higgins 1116 Apache Warrior 23000
31 Hofmann 1029 Horseshoe Falls 15000
32 Ibe 1006 House Remembered 700
33 Indiana 1046 Immediate Gratification 1500
34 Ingraham 1031 Inside/Out 3500
35 Irvin 1107 Striking It Rich 1750
36 Kerrihard 1051 Night Version 7000
37 Kollasch 1088 Lessons 3700
38 Kritz 1045 Leaf Patterns 2100
1100 Hungry Cowboys 750
39 Lerman 1094 Life Is Sweet 25000
40 Long 1106 Horse Corral 12500
41 Lowney 1062 Cowboy and Saddle 18000
42 Lundquist 1032 Rising Sun 2000
1060 Story Sticks 650
43 Lutes 1044 Mexican Fiesta 14000
44 Maglich 1047 Medicine Man 2500
45 McGraw 1014 Plenty 500
46 McIver 1015 Punch 10000
47 Meglech 1023 Shooting the Rapids 1300
1027 Mountain Climber 4700
1035 Nature/Nurture 1300
1040 Night on the Praire 1300
1065 Moonlite 1300
1092 Dressing Up 1300
48 Metz 1024 Spirit and Nature 592
49 Miller 1067 Owl in Flight 7000
50 Mogan 1001 Red Rock Mountain 18000
1028 Tired Cowboy 4700
1054 Snake Charmer 4500
1068 Moonlight 9750
1069 Renaissance 5500
1113 Shadow House 5500
1114 Storytelling at the Campfire 18000
51 Motherwell 1064 Spirit Columns 7000
52 Novarre 1002 Offerings 10000
53 Odiezma 1089 Life Lessons 4125
54 Ortega 1091 Stone Palette 11500
55 Parker 1074 Storm on the Rise 8000
56 Penn 1098 Sweet Project 592
57 Pierobon 1048 Comfy Chair 800
58 Prinzen 1101 The Red Door 10000
59 Quiroz 1080 The Dust Behind 18000
60 Rath 1058 The Gathering 250
61 Reed 1019 The White Heart 9300
1095 The Spirit 20000
62 Rissman 1079 Carrying the Mail 8000
1093 Antelopes 12500
1110 Three Sisters 6500
63 Rogers 1085 Traces 20000
64 Roman 1004 Seeking Shelter 52000
1083 Untitled 2500
65 Schenck 1016 Untitled 6000
66 Scherzel 1026 Untitled (couple) 4000
1057 Untitled 4500
67 Scholder 1086 Untitled (desert landscape) 18000
68 Senior 1025 Profile of a Woman 625
69 Shenal 1022 The Cowboy 4200
70 Statom 1104 Untitled 1800
71 Swartz 1010 Untitled (land with adobe) 800
72 Tidwell 1111 Untitled (man and crucifix) 3200
73 Turrell 1020 Untitled (Man holding coat) 3000
74 Udinotti 1012 Man on Horseback 8000
75 VanColler 1097 Untitled (Sea) 2800
76 Waid 1066 Untitled (still life) 19500
77 Werner 1033 Untitled (Woman abstract) 2500
1108 Untitled Mural 400
78 Wittner 1061 Untitled Mural 3520
79 Wright 1071 Ride the Rapids 300
1076 Ride the Bronco 1500
80 Xie 1105 Meteor Show 10000
81 Yasami 1087 Three Woman 20000
82 Zischke 1007 Homage to the Ancestors 1200









