CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

fwrite or f_write and what library do they need?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Koska



Joined: 05 Dec 2014
Posts: 3

View user's profile Send private message

fwrite or f_write and what library do they need?
PostPosted: Sat Dec 20, 2014 1:41 pm     Reply with quote

Hello,

I need to use the function fwrite() in my code. From the link below I understood it is necessary to include at the top the library

Code:
#include<stdio.h>


http://www.tutorialspoint.com/c_standard_library/c_function_fwrite.htm

But I built my project with CCS 5 and I got the following error:

*** Error 12 "code.c" Line 280(9,10): Undefined identifier -- fwrite

So I went to the folder drivers into PICC and I opened to check the content of stdio.h and I could see there is nothing there about fwrite.

Code:

///////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,2003 Custom Computer Services           ////
//// This source code may only be used by licensed users of the CCS C  ////
//// compiler.  This source code may only be distributed to other      ////
//// licensed users of the CCS C compiler.  No other use, reproduction ////
//// or distribution is permitted without written permission.          ////
//// Derivative programs created using this software in object code    ////
//// form are not restricted in any way.                               ////
///////////////////////////////////////////////////////////////////////////

#ifndef _STDIO
#define _STDIO
#include <string.h>
#ifndef getc
#define getc getch
#define getchar getch
#define puts(s) {printf(s); putchar(13); putchar(10);}
#define putc putchar
#endif
/* maps error number to an error message. Writes a sequence of characters to
stderr stream thus: if s is not null then string pointed to by s follwed by
a colon (:) and a space and the appropriate error message returned by strerror
function with argument errno

Returns: no value
*/

#ifdef _ERRNO
void perror(char *s)
{
  if(s)
  fprintf(STDERR,"%s: ",s);
  fprintf(STDERR,"%s\r\n",strerror(errno));
}
#endif
#endif


So my question is: Should I include another function and what I read is not correct for CCS, or the problem is my version of CCS has a corrupted stdio.h? Probably the problem is completly different to what I'm thinking.



In Addition, I was reading in this forum trying to find a solution on my own, and I saw some people use f_write() instead. Is is a better option? I couldn't find much information about f_write

Thank you very much for your help!


Last edited by Koska on Sat Dec 20, 2014 4:17 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Dec 20, 2014 2:55 pm     Reply with quote

I assume this is for an SD card. What drivers are you using to interface
to the SD card ?

If you use the CCS fat.c driver, then the comments at the top of the file
say to use the fatwrite() function. The file is in this directory:
Quote:
c:\program files\picc\drivers\fat.c



Quote:
or the problem is my version of CCS has a corrupted stdio.h?

stdio.h is not corrupted.
Koska



Joined: 05 Dec 2014
Posts: 3

View user's profile Send private message

PostPosted: Sat Dec 20, 2014 3:49 pm     Reply with quote

Thank you for your reply PCM Programmer. But actually I'm not trying to write on a SD card. I'm trying to send information that I previously read from a SD card via Bluetooth.

So what I have is a stream called BT:
Code:

#use RS232(UART, baud = 115200, xmit = PIN_C6 ,rcv = PIN_C7, PARITY = N, bits = 8, stop = 1, stream = BT)

char buffer_data[129];
int NumOfBytes = 128;
int32 Address = 0xXXXXXXXX;//any address

//Here I read from the SDcard. I wrote this function using mmcsd.c
GetFileContent(Address, NumOfBytes,  &buffer_data);


At this point I have in buffer_data the bytes I want to send. What I was doing before, and worked perfectly with .txt was this:

Code:
buffer_data[NumOfBytes] = 0x00;// To set an end of the relevant data
printf(BT, buffer_data);


But the problem is when I try to send a .pdf because in memory sometimes appears the character 0x00, so printf don't send all the content of buffer_data. It will stop when finds 0x00.

So I was looking for another function where I could include the number of bytes I want that are sent. And I read about fwrite(), and I changed the printf() for:
Code:

fwrite (buffer_data , sizeof(char), NumOfBytes, BT);



And here is where I found the problem I mention above.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 21, 2014 8:19 pm     Reply with quote

There is no built-in fwrite() function. I suggest that you use fputc()
in a for() loop to send the data.
Ttelmah



Joined: 11 Mar 2010
Posts: 19350

View user's profile Send private message

PostPosted: Mon Dec 22, 2014 3:55 am     Reply with quote

Understand, that 'fwrite' is for dealing with a file.

The PIC unless you have an added 'filesystem' like an SD card attached, does not have a filesystem available/involved. Hence no fwrite type functions....
Koska



Joined: 05 Dec 2014
Posts: 3

View user's profile Send private message

PostPosted: Mon Dec 22, 2014 6:29 am     Reply with quote

Ok. Thank you for your answers and recommendations.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group