Printf not working

09 Apr 2010 . Edited: 09 Apr 2010

Hi,  im having a trouble with printf function. Each printf() doesnt work beside the first one. Does any one know why it wont work ?

My output in terminal for the first run (when the config.cfg does not exist) is only :

"Config not found!"

and should be :

"Config not found!

File Saved

File Saved 2"

Fprintf() work correctly the file is created and text added.

Here's my code:


#include "mbed.h"
#include "SDFileSystem.h"
#include <stdio.h>
#include <string.h>
#include <iostream>

Serial pc(USBTX, USBRX); // tx, rx
LocalFileSystem local("local");

SDFileSystem sd(p5, p6, p7, p8, "sd");

DigitalOut PowerLed(LED1);
DigitalOut txLed(LED2);

Ticker timeout1;
Ticker secInterval;
Timeout ledDelay;
time_t seconds; /// = time(NULL);

int main() {
    FILE *pFile = fopen("/sd/config.cfg", "r");
    if (pFile == NULL) {
        printf("Config not found!\n");
        pFile = fopen("/sd/config.cfg", "a");
    if (pFile == NULL) {
        printf("Config 2 not found");
    } else {
        fprintf(pFile, "Hello World !\n");
        fprintf(pFile, "Hello World 2!\n");
        printf("File Saved");
    printf("File Saved 2");
09 Apr 2010

Hi Maciej,

Try putting a newline character on your printf's:

       printf("File Saved\n");
This will make sure printf flushes it's buffer, and you should see it fine (unless it is another problem I haven't spotted!).


10 Apr 2010



with "\n" works ..!