Thread: File_Graper

  1. #1
    life is a nightmare
    Join Date
    Apr 2007
    Posts
    127

    File_Graper

    hy all i am facing a problem in this code
    Code:
    /*file.c */
    
    #include "file.h"
    
    #include<string.h>
    
    char  *get_file_path(char *buffer)
    
    {
    
         int count;
    
         char *path;
    
         for(count=0;buffer[count]!='\0';count++)
    
         {
    
         if(buffer[count]=='/')
    
         {
    
         path=&buffer[count];
    
         break;
    
         }
    
         }
    
         for(count=0;path[count]!='\0';count++)
    
         {
    
         switch((*buffer+count))
    
         {
    
         case ' ':
    
              path[count]='\0';
    
              break;
    
              }
    
              }
    
              
    
         return path;
    
         }
    
         char *get_file_name(char *buffer)
    
         {
    
              char *name;
    
              name=strrchr(buffer,'/');
    
              return name;
    
              }
    Code:
    /*file.h*/
    #if defined(file)
    
    
    #else
    
    #define file
    
    char *get_file_path(char *buffer);
    
    char *get_file_name(char *buffer);
    
    #endif
    Code:
    /* source code*/
    
    #include<stdio.h>
    
    #include<string.h>
    
    #include "file.h"
    
    #define BUF 250
    
    main()
    
    {
    
    FILE *fp,*lp,*cp,*pp;
    
    char word[10],copy[BUF],buffer[BUF],*path,*name;
    
    printf("\nHy I am   What We Gonna Do Is Getting The Files That You Will Enter It's 
    Extnasion:");
    
    fgets(word,10,stdin);
    
    fp=fopen("c:\hh.txt","rb");
    
    
    lp=fopen("log.txt","rb");
    
    if((fp==NULL)&&(lp==NULL))
    
    fprinf(stderr,"\nError In Opining File IN File &#37;s Line %d",__FILE__,__LINE__);
    
    while((fgets(buffer,BUF,fp))!=NULL)
    
    {
    
     path=get_file_path(buffer);
    
     name=get_file_name(path);
    
     if(((pp=fopen(path,"rb"))!=NULL)&&(cp=fopen(name,"ab"))!=NULL)
    
     {
    
     while((fgets(copy,BUF,pp))!=NULL)
    
     {
    
     fputs(copy,cp);
    
    }
    
    fclose(pp);
    
    fclose(cp);
    
    }
    
    
    
    
    
    
    
    
    
    }
    
    fprintf(stderr,"\nComplet");
    
    
    
    
    
    
    
    
    
    fclose(fp);
    
    
    
    fclose(lp);
    
    
    
    return (0);
    
    
    
    
    
    
    
    }
    i am using dev-cpp compiler

    and i can't compile it the error is

    [Linker error] undefined reference to `get_file_path'
    [Linker error] undefined reference to `get_file_name'
    ld returned 1 exit status
    what is the problem now ?


    help
    Last edited by St0rM-MaN; 05-04-2007 at 01:54 PM.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Do you have file.c included as a file in your project?
    If you understand what you're doing, you're not learning anything.

  3. #3
    life is a nightmare
    Join Date
    Apr 2007
    Posts
    127
    thats a sure thing man

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Here's why it's bad to name your macros carelessly.
    Code:
    /*file.h*/
    #if defined(file)
    
    #else
      #define file
      char *get_file_path(char *buffer);
      char *get_file_name(char *buffer);
    #endif
    The logic here is fine, however, when you define file the preprocessor eventually goes through the code, preparing it for compilation and runs into an unforseen problem: You've also used the phrase "file" as part of a function name or two, and such things are not exempt from #defined replacements. I'm positive the compiler sees something like this:
    Code:
    char *get__path(char *buffer);
    char *get__name(char *buffer);
    get_file_path and get_file_name still don't have a prototype, so the linker pukes.

    I'd recommend a macro far more unique for this purpose.
    Last edited by whiteflags; 05-04-2007 at 02:26 PM.

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Something like FILE_H__ is something I commonly see.
    If you understand what you're doing, you're not learning anything.

  6. #6
    life is a nightmare
    Join Date
    Apr 2007
    Posts
    127
    thanks all
    when i removed
    Code:
     #include<stdlib.h>
    from file.c
    it works
    but
    the program isn't work
    why?
    1-i didn't test functions
    2-i assumed that the program will work as soon as i write functions
    3-i didn't get the macro stuff
    do you mean like that for example
    Code:
    #define func(value) func{//code goes here}
    ??? do you mean that?
    i am not on my machine to tray it now
    but i will tray it as soon as i come back
    really thanks to all you

Popular pages Recent additions subscribe to a feed