Thread: Can anyone tell me whats wrong?

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    14

    Can anyone tell me whats wrong?

    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;
      }
    
    
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    for(status = fscanf(inputfile,"%s", scan); status!=EOF; (inputfile,"%s", scan))
    What exactly are you trying to do here? What's with the final segment of the for loop? It isn't a function call, so what is it supposed to be? It doesn't do anything.

    [edit]
    I'm guessing you want to follow this logic:
    Code:
    while not at the end of the file
        scan an army from the file into a new node
        add the node to the list
    Break each step down into the steps needed to do each step.
    [/edit]

    Quzah.
    Last edited by quzah; 05-16-2004 at 04:12 AM.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Apr 2004
    Posts
    14
    thanks i figured it out

    hehe (i have strange programming habits)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM