zhangyanping
驱动小牛
驱动小牛
  • 注册日期2003-02-23
  • 最后登录2004-07-23
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1115回复:4

一个很简单的问题,送20分!

楼主#
更多 发布于:2003-03-31 14:57
那位高手能够讲述一下下面两个函数的意义?
fgets(line, sizeof(line), stdin);
sscanf (line, \"%x\", &addr);

在调试过程中,我想连续读自己确定数目的长字,但是,为什么每次读得都是同一个数阿,怎么能让偏移地址加4阿?

还有就是请问那个函数可以获得PCI总线这边物理地址阿?局部空间得地址应该是BAR2和BAR3的内容吧!

对了,我用的片子是9054,环境是WINDRIVER!
zhangyanping
驱动小牛
驱动小牛
  • 注册日期2003-02-23
  • 最后登录2004-07-23
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-04-10 10:16
已经给分了,楼上两位,感谢能给予那么详细的回答!

驱动开发网好几天不能登录了,所以,今天才看到,虽然我最终理解了fgets()和sscanf()的用法,但是,现在是更明白了,感谢!
beiqiuke
驱动牛犊
驱动牛犊
  • 注册日期2002-08-18
  • 最后登录2005-08-22
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2003-04-09 12:55
The sscanf function reads data from buffer into the location given by each argument. Every argument must be a pointer to a variable with a type that corresponds to a type specifier in format. The format argument controls the interpretation of the input fields and has the same form and function as the format argument for the scanf function; see scanf for a complete description of format. If copying takes place between strings that overlap, the behavior is undefined.

swscanf is a wide-character version of sscanf; the arguments to swscanf are wide-character strings. sscanf does not handle multibyte hexadecimal characters. swscanf does not handle Unicode fullwidth hexadecimal or “compatibility zone” characters. Otherwise, swscanf and sscanf behave identically.
Example
/* SSCANF.C: This program uses sscanf to read data items
?  from a string named tokenstring, then displays them.
 */

#include <stdio.h>
void main( void )
{
char  tokenstring[] = “15 12 14...”;
char  s[81];
char  c;
int   i;
float fp;

/* Input various data from tokenstring: */
sscanf( tokenstring, “%s”, s );
sscanf( tokenstring, “%c”, &c );
sscanf( tokenstring, “%d”, &i );
sscanf( tokenstring, “%f”, &fp );

/* Output the data read */
printf( “String    = %s\\n”, s );
printf( “Character = %c\\n”, c );
printf( “Integer:  = %d\\n”, i );
printf( “Real:     = %f\\n”, fp );
}

Output
String    = 15
Character = 1
Integer:  = 15
Real:     = 15.000000


beiqiuke
驱动牛犊
驱动牛犊
  • 注册日期2002-08-18
  • 最后登录2005-08-22
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2003-04-09 12:53
The fgets function reads a string from the input stream argument and stores it in string. fgets reads characters from the current stream position to and including the first newline character, to the end of the stream, or until the number of characters read is equal to n
wxl_50685330
论坛版主
论坛版主
  • 注册日期2002-11-19
  • 最后登录2018-09-25
  • 粉丝0
  • 关注0
  • 积分1000分
  • 威望521点
  • 贡献值0点
  • 好评度419点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2003-04-04 18:32
fgets(char *,int,FILE);
从FILE中读int个字符到char *里面(注意遇到换行也将停止)
你的line是不是char *?如果是sizeof(char *)==2,当然不对了,你要换一种方式确定读出的字节数.
sscanf(const char *,FORMAT,ADDR)
把const char *的字符按FORMAT格式读到ADDR地址开始的地方
根据地的兄弟们,团结就是力量
游客

返回顶部