Hey,
you could probably see that i am tryng to make a linked list program.
When I compile the prog, there are no errors. The problem is somewhere in my methodology.
Can anyone help me out, to steer me straight.
Thanks
Code:
#include <stdio.h>
#include <string.h>
struct army {
struct army *next;
char section_name[81];
char sub_name[81];
int points;
char discription[500];
};
int i=0, status, y;
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(status = fscanf(inputfile,"%s", scan); status!=EOF; (inputfile,"%s", scan))
{
Army = (struct army *)malloc(sizeof(struct army));
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");
}
}
Army = Army->next;
Army = (struct army *)malloc(sizeof(struct army));
}
while(1)
{
printf("%s\n%d\n%s\n", Army->sub_name, Army->points, Army->discription);
Army = Army->next;
}
}