Thread: file is not of required architecture warning

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    67

    file is not of required architecture warning

    here is my hash table code that reads in a file and puts it into a hash table and handles collisions with a linked list approach.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    
    typedef struct List { char *word; struct List *next; } List;
    
    #define HASHSIZE 65536
    #define LEN 50
    
    static struct List *hashtab[HASHSIZE];
    
    static FILE *open_file (char *file, char *mode)
    {
      FILE *fp = fopen (file, mode);
    
      if (fp == NULL){
        perror ("Unable to open file");
        exit (EXIT_FAILURE);
      }
    	return fp;
    }
    
    List *list_alloc (void)
    {
    	List *tmp = calloc (1, sizeof (List));
    		if (tmp == NULL){
    			fprintf (stderr, "Error: calloc ()\n");
    			}
    			tmp -> word = NULL;
    			tmp -> next = NULL;
    			return tmp;
    }
    
    
    int is_punctuation (int a)
    {
        return a == ' ' || a == '\n' ||
               a == EOF || a == ',' || 
               a ==';' || a =='.'||
               a =='!' || a =='?' || 
               a ==':' || a =='`';
    }
    
    
    unsigned rot_hash (void *key) 
    {
    	unsigned char *p = key;
    	unsigned h = 0;
    	int i;
    	
    	for (i = 0; i < strlen(key); i++)
    		h = (h << 4) ^ (h >> 28) ^ p[i];
    	return h % HASHSIZE;
    }
    
    void install (char *s)
    {
    	List *tmp = NULL;
    	unsigned int h = rot_hash (s);
    	if (hashtab[h] -> word == NULL){
    		hashtab[h] = list_alloc ();
    		strcpy (hashtab[h] -> word, s);
    		printf ("Put value into empty space\n");
    	}else{
    		for (tmp = hashtab[h]; tmp != NULL; tmp = tmp -> next){	
    			if (tmp -> next == NULL){
    				tmp -> next = list_alloc ();
    				strcpy (tmp -> next -> word, s);
    				printf ("Put value into a linked list\n");
    				break;
    			}
    		}
    	}
    }
    				
    
    int main (int argc, char *argv[])
    {
    	int x;
    	char a, word[LEN];
    	x = 0;
    	FILE *fp = open_file (argv[1], "r");
    	do{
    		a = fgetc (fp);
    		if (is_punctuation(a)){
    			if (x != 0){
    				word[x] = '\0';
    				install (word);
    				x = 0;
    				}
    		}else{
    			word[x] = tolower(a);
    			x++;
    			}
    	} while (a != EOF);
    	fclose (fp);
    	return 0;
    }
    for some reason i keep getting a bus error and a warning that says the file is not of required architecture but i don't see any mistakes in the code. where am i going wrong?
    thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Which OS/Compiler are you talking about?

    The exact text of the error message(s), and what you did to compile the code would help.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    67
    I am compiling on Mac OS X 10.5 using GCC compiler.
    this in the command i use: gcc hcopy.c -Wall hcopy
    and this is the warning: ld: warning in hcopy, file is not of required architecture
    thanks for help

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Maybe
    gcc -o hcopy -Wall hcopy.c

    Without the -o, gcc will treat your resulting executable as an input file, not an output file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    67
    thanks. it doesn't give the warning anymore but when i run the program it still says bus error. I don't see any obvious mistakes in the code, so where could i be going wrong?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well one cause would be not passing a command line parameter.
    Which you don't check to see if it exists, nor do you check to see if the file was opened successfully.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    67
    nope i didnt forget to pass the command line parameter, could it be something to do with me using calloc in list_alloc as opposed to malloc?

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    You're not allocating any space for ->word either, before you do a copy.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    Dec 2007
    Posts
    67
    i thought calling list_alloc before i hash the word would allocate the space required. I am sorry if i am being a little slow, but still don't understand where my mistake is.
    thanks

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    p->word = malloc( strlen(s) + 1 );
    strcpy( p->word, s );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM