c - how to pass a char variable to FS_write() function -- EmFile? -


i`m trying use emfile library embedded programing based on c.

this structure of fs_write in api documentation :

u32 fs_write (fs_file * pfile,               const void * pdata,               u32 numbytes); 

i want write own function later use like:

void sd_write_to_file(char buff) {      if(pfile)     {      if(0 != fs_write(pfile, buff, strlen(buff)))      {      }     else     {         fontwrite_position(100,148);//text written position         putstringlcd("failed write data file");     }     }  } 

the problem when call function , pass char value, can`t use fs_write. example:

    sprintf(tempwordshow, "%f", realsamples[realsamplescounter]);      sd_write_to_file(tempwordshow); 

realsample[ ] float , tempwordshow char.

note if use function :

    if(0 != fs_write(pfile, "0123456789", 10u)) 

it working.

i think problem way of passing data function .

any ideas?

thanks

in general, make sure functions take pointer argument indeed receiver pointers. , conversely if intend use pointer, should make sure function's signature takes pointer argument.

in particular case intention seems to write buffer of characters (which can passed function passing pointer memory location corresponding buffer), in likelyhoods more single char. correspondingly, signature of sd_write_to_file should changed to:

  void sd_write_to_file(const char* buff) 

you may have similar problem sprintf's first argument expected of type char* whereas mention tempwordshow of type char (note there should memory allocated wherever tempwordshow points to). if wasn't trivial typo in question, have convert tempwordshow's declaration such as:

  char tempwordshow[40]; // 40-char buffer should large enough %f 

as final note, strlen designed handle null-terminated character sequences (or strings). so, if intend use function strictly null-terminated strings, fine. otherwise, may find more appropriate pass along length of buffer wish write (something sd_write_to_file(const char* buff, int bufferlength)).


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -