Redeclaration Error

This is a discussion on Redeclaration Error within the C Programming forums, part of the General Programming Boards category; I wasted my whole day trying to find this silly error but didn't get through I am trying to compile ...

  1. #1
    Samuel shiju's Avatar
    Join Date
    Dec 2003
    Posts
    41

    Redeclaration Error

    I wasted my whole day trying to find this silly error but didn't get through

    I am trying to compile

    Code:
    /*
    file: filesearch.c
    */
    #include <string.h>
    #include <windows.h>
    
    #include "filesearch.h"
    #include "stack.h"
    
    void getCurrentPath(char *path)
    {
    	GetCurrentDirectory(MAX_PATH,path);
    }
    
    void searchpath(char *path,char *pattern,struct strData **filestack)
    
    {
    	HANDLE hsearch;
    	WIN32_FIND_DATA FileData;
    	char tempdata[MAX_PATH];
    	struct stkData *dirstack,tempstack;
    	initstack(&dirstack);
    	initstack(filestack);
    	
    	if(SetCurrentDirectory(path)){
    		if((hsearch=FindFirstFile(pattern,&FileData)) != INVALID_HANDLE_VALUE){
    			do{
    				if(!(FileData.cFileName == "." || FileData.cFileName == "..")){
    					if (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
    						strncpy(tempstack.data,FileData.cFileName,strlen(FileData.cFileName));
    						push(&dirstack,tempstack);
    					}else{
    						strncpy(tempstack.data,FileData.cFileName,strlen(FileData.cFileName));
    						push(filestack,tempstack);
    					}
    				}
    			}while(FindNextFile(hsearch, &FileData));
    			FindClose(hsearch);
    		}
    		while(!isEmpty(&dirstack)){
    			tempstack = pop(&dirstack);
    			searchpath(tempstack.data,pattern,filestack);
    		}
    	}
    
    	
    }
    these are the header files

    Code:
    #ifndef _FILESEARCH_H
    #define _FILESEARCH_H
    void getCurrentPath(char *);
    
    void searchpath(char *,char *,struct strData **);
    
    #endif
    Code:
    #ifndef _STACK_H
    #define _STACK_H
    #define PATHLENGTH 260
    
    struct stkData{
    	char data[PATHLENGTH];
    	int status;
    	struct stkData *next;
    };
    
    void initstack(struct stkDat..........);
    int isEmpty(struct stkDat..........);
    void push(struct stkDat..........,struct stkData);
    struct stkData pop(struct stkDat..........);
    #endif
    I am getting this error
    Code:
    D:\Project\C\stack>lcc filesearch.c
    Error filesearch.c: 14  redeclaration of 'searchpath' previously declared at d:\project\c\stack\filesearch.h 4
    1 errors, 0 warnings
    Last edited by shiju; 09-01-2004 at 08:29 AM.
    Be conservative in what you do, be liberal in what you accept from others.
    RFC 793, "Transmission Control Protocol."


  2. #2
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    what is a struct strData?
    hello, internet!

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    Given the name of the parameter, I guess "strData" should have been "stkData"

    > FileData.cFileName == "." || FileData.cFileName == ".."
    This is not how you compare strings in C

    > strncpy(tempstack.data,FileData.cFileName,strlen(F ileData.cFileName));
    This isn't going to append a \0 on to the end of the buffer.
    Nor is it going to protect you from buffer overflow.

    strncpy(tempstack.data,FileData.cFileName,sizeof(t empstack.data));
    tempstack.data[sizeof(tempstack.data)-1] = '\0';

    > push(&dirstack,tempstack);
    I hope this copies tempstack to something you allocate, otherwise all your stack elements are going to be referring to the same local variable.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Samuel shiju's Avatar
    Join Date
    Dec 2003
    Posts
    41
    Thanks
    Be conservative in what you do, be liberal in what you accept from others.
    RFC 793, "Transmission Control Protocol."


  5. #5
    Samuel shiju's Avatar
    Join Date
    Dec 2003
    Posts
    41
    >I hope this copies tempstack to something you allocate, otherwise all your stack elements are going to be referring to the same local variable

    I think I am doing right

    Code:
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include"stack.h"
    
    void initstack(struct stkData **top){
    	*top = NULL;
    }
    
    
    int isEmpty(struct stkData **top){
    	return (*top == NULL);
    }
    
    void push(struct stkData **top,struct stkData data){
    	struct stkData *newdata;			
    	newdata = malloc(sizeof(struct stkData));
    	strcpy(newdata->data,data.data);
    	newdata->status = data.status;
    	newdata->next = *top;
    	*top = newdata;
    }
    
    struct stkData pop(struct stkData **top){
    	struct stkData *temp, temp2;
    	isEmpty(top);
    	temp = *top;		
    	temp2 = *temp;
    	*top = (*top)->next;
    	free(temp->data);
    	free(temp);
    	return temp2;
    }
    Tell me is there any glitch in this code.
    Be conservative in what you do, be liberal in what you accept from others.
    RFC 793, "Transmission Control Protocol."


  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    Yeah, your pop() function is way off.

    For example
    - calling isEmpty() without testing the result
    - calling free on something which was never allocated
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Samuel shiju's Avatar
    Join Date
    Dec 2003
    Posts
    41
    Thanks once again
    Be conservative in what you do, be liberal in what you accept from others.
    RFC 793, "Transmission Control Protocol."


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21