Hi,
You may have read alot of my previous posts about linked lists, this is my last resort. I have no idea what I am doing. Everyone is assuming that I know what i am doing, or I know what they are writing about. In reality I dont, I know so far how to setup a struct and fscanf into it. It took some time but i figured it out. When I read the linked list posts I see those "->" thingies, the Node and pointer stuff.
Could anyone take the time and explain it out to me, or take a look at my code and tell me what I have to do. Remember go slow, I am a relative newbie.![]()
And this is the text file I am referencing through the programCode:#include <stdio.h> #include <string.h> typedef struct army { struct army *next; char section_name[81]; char sub_name[81]; int points; char discription[500]; }; int i=0; char name[81]="<name>", scan[81], descrip[10]="<descrip>"; char temp_word[81]; char temp_close[8]="</name>"; char temp_close2[10]="</descrip>"; struct army Army; int main() { FILE *inputfile; inputfile = fopen("Rune2.txt","r"); if (inputfile == NULL) { printf("error opening file"); } else { printf("File opened successfully. Loading data...\n\n"); } for (fscanf(inputfile," %s ", temp_word); temp_word!=NULL; fscanf(inputfile," %s ", temp_word)) { if (strcmp(temp_word, temp_close)==0) break; strcat(temp_word, " "); strcat(Army.sub_name, temp_word); } fscanf(inputfile,"%d", &Army.points); fscanf(inputfile,"%s", scan); for (fscanf(inputfile," %s ", temp_word); temp_word!=NULL; fscanf(inputfile," %s ", temp_word)) { i++; if (strcmp(temp_word, temp_close2)==0) break; strcat(temp_word, " "); strcat(Army.discription, temp_word); if (i==9) { i=0; strcat(Army.discription, "\n"); } } printf("%s\n%d\n%s\n", Army.sub_name, Army.points, Army.discription); }
Runes2.txt
Code:<name> Master Rune of Snorri Spangelhelm </name> 75 <descrip> Any blows struck by a weapon engraved with this rune will always hit. No roll to hit necessary. </descrip> <name> Master Rune of Skalf Blackhammer </name> 75 <descrip> Any weapon Bearing this rune will automatically wound if it hits. No roll to wound required. Use characters strength for hte save modifier. </descrip> <name> Master Rune of Alaric the Mad </name> 50 <descrip> This rune cancels an opponents armour saving throw. When wounded by this weapon, the target is not allowed an armour saving throw of any kind. </descrip>



LinkBack URL
About LinkBacks




