parse error

This is a discussion on parse error within the C Programming forums, part of the General Programming Boards category; Can someone tell me what this error means: parse error before string constant Here is my code - for some ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    35

    parse error

    Can someone tell me what this error means: parse error before string constant

    Here is my code - for some reason I can't get the SPRINTF line to work because of the error... Thanks

    Code:
    #include<linux/kernel.h>
    #include<linux/module.h>
    #include<linux/proc_fs.h>
    #include<asm/uaccess.h>
    
    #define BUF_LEN 50
    #define MESSAGE_LENGTH 80
    
    static char Message[MESSAGE_LENGTH] ;
    char message[MESSAGE_LENGTH+30] ;
    
    static ssize_t module_output(
       struct file *file,
       char *buf,
       size_t len,
       loff_t *offset);
    
    static ssize_t module_input(
       struct file *file,
       const char *buf,
       size_t length,
       loff_t *offset);
       
    sprintf(message, "Last input:%s", Message) ;
    
    int read_my_clock( char *a, char **b, off_t c, int d, int e)
    {
       printk(KERN_ALERT, "\nread_my_clock\n") ;
       /* this is the function that I write to read
          the clock file info that I created in proc
       */
    }
    
    struct proc_dir_entry dc_clock_mod_file = {
      0,
      12,
      "dc_clock_mod",
      S_IFREG | S_IRUGO,
      1,
      0,
      0,
      BUF_LEN,
      NULL,
      read_my_clock,
      NULL
    };
    
    int init_module()
    {
       return proc_register(&proc_root, &dc_clock_mod_file);
    }
    
    void cleanup_module()
    {
       proc_unregister(&proc_root, dc_clock_mod_file.low_ino) ;
    }

    I am using the GCC compiler so you may have to use this line to compile.

    gcc -I /usr/include -c -D__KERNEL__ -DMODULE <filename>

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >sprintf(message, "Last input:%s", Message) ;

    This line has to be inside one of your functions. Right now sprintf() will never get called, as it's part of your global declarations.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    35

    great

    Youre right. I moved sprintf inside my function and it worked...

    Thanks

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    35

    using sprintf to print to /proc file

    Okay, I move the sprintf line inside my init_module function... the code now compiles okay...

    I am trying to use sprintf to write a string from the message buffer to my file that I create in /proc. The module name is dc_clock_mod - seen in my code.... here is the new code. Thanks



    Code:
    #include<linux/kernel.h>
    #include<linux/module.h>
    #include<linux/proc_fs.h>
    #include<asm/uaccess.h>
    
    #define BUF_LEN 50
    #define MESSAGE_LENGTH 80
    
    static char Message[MESSAGE_LENGTH] ;
    char message[MESSAGE_LENGTH+30] ={"873675 97325"} ;
    
    static ssize_t module_output(
       struct file *file,
       char *buf,
       size_t len,
       loff_t *offset);
    
    static ssize_t module_input(
       struct file *file,
       const char *buf,
       size_t length,
       loff_t *offset);
       
    
    int read_my_clock( char *a, char **b, off_t c, int d, int e)
    {
       printk(KERN_ALERT, "\nread_my_clock\n") ;
       /* this is the function that I write to read
          the clock file info that I created in proc
       */
    }
    
    struct proc_dir_entry dc_clock_mod_file = {
      0,
      12,
      "dc_clock_mod",
      S_IFREG | S_IRUGO,
      1,
      0,
      0,
      BUF_LEN,
      NULL,
      read_my_clock,
      NULL
    };
    
    int init_module()
    {
       return proc_register(&proc_root, &dc_clock_mod_file);
       sprintf(message, "Last input:%s", Message) ;
    }
    
    void cleanup_module()
    {
       proc_unregister(&proc_root, dc_clock_mod_file.low_ino) ;
    }

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I am trying to use sprintf to write a string from the message buffer to my file that I create in /proc.
    You don't use sprintf to write to files (unless you've redirected stdout, and if you did, why on earth would you?). You use fprintf.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    35

    fprintf and sprintf

    fprintf is onfly available through the stdio.h library.

    I can't use it. Kernel modules in linux will not recognize fprintf...


    I figured it out. Thanks for the input.

  7. #7
    King of the Internet Fahrenheit's Avatar
    Join Date
    Oct 2001
    Posts
    128
    Um, sprintf is defined in stdio.h as well.

    http://www.cplusplus.com/ref/cstdio/sprintf.html

  8. #8
    Registered User
    Join Date
    Sep 2002
    Posts
    35
    I can't use it. Kernel modules in linux will not recognize fprintf...

    Problem solved, anyway...

    I found that I can use copy_from_user() to get the desired results...


    Peace

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 06:33 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  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