LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-27-2004, 04:34 AM   #1
snigglyfox
LQ Newbie
 
Registered: Apr 2004
Posts: 4

Rep: Reputation: 0
sprintf not working in char driver module


Howdy,

I'm writing a character driver and am getting some wierd behavior from the command sprintf. Here is the basic code.

----------------------------------------------------------------------
ssize_t driver_read (struct file *filp, char *buf, size_t count, loff_t *ppos) {
int bytes = 0;
char output[256];
int myint = 12;
float myfloat = 1.234567;

bytes = sprintf(output, "int = %i float = %f \n", myint, myfloat);

copy_user (buf, &output, bytes);

return bytes;
}
-----------------------------------------------------------------------


The output to this is

int = 12 float = %f


Does anyone know why floats are not working for sprintf?

cheers
Rich
 
Old 04-27-2004, 01:22 PM   #2
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
i donno but im lookin at the vsnprintf source [ /usr/src/linux/lib/vsprintf.c] and there is NO conversion available for printing floating point numbers. there is no e, f, or g ??? anyone else?
 
Old 04-27-2004, 01:25 PM   #3
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
found this:
Quote:
[printk()] int printk(const char* fmt, ...)

#include <linux/kernel.h>

printk() is a version of printf() for the kernel, with some restrictions. It cannot handle floats, and has a few other limitations, which are documented in kernel/vsprintf.c. It takes a variable number of arguments:
printk uses vsprintf so apparently u can't print floating point numbers. taht is rather retarded. i wonder how hard it would be to add?? i shall see
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
char device module the_uplink2x Programming 2 05-24-2005 10:53 PM
modprobe: Can'l locate module char-major-108 Guvvy Linux - Newbie 5 02-03-2005 09:57 PM
modprobe: Can't locate module char-major-4 Bruce Hill Slackware 4 01-30-2004 10:45 PM
module char.major.lo.135 safrout Linux From Scratch 2 11-21-2002 08:16 PM
Module--char-major-10-135 Hartford Linux - General 2 05-21-2002 10:14 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration