fprintf

fprintf return success but can't write to an existin file

In my codes, fprintf return successful by returning the number of bytes written in STREAM, but in the actual file the string I put is not there. ...

Is fprintf thread-safe?

Is fprintf thread-safe? The glibc manual seems to say it is, but my application, which writes to a file using single call to fprintf() seems to be intermingling partial writes from different processes. edit: To clarify, the program in question is a lighttpd plugin, and the server is running with multiple worker threads. Looking at the...

How can I use fprintf and write to a pipe?

I created a pipe and I used dup2() to overwrite streams 1 & 2 (stdout & stderr) into those pipes. Now I wish to use fprintf to write to stream 1 or 2, but my program doesn't seem to be receiving anything on the other side of the pipe. I've tried using printf(), but I'm not sure if this writes to stdout or stream 1 by default. If it writ...

Displaying information from MATLAB without a line feed

Is there any way to output/display information from a MATLAB program without an ending line feed? My MATLAB program outputs a number a bit now and then. Between outputting the number the program does a lot of other stuff. This is a construct mainly to indicate some kind of progress and it would be nice not to have a line feed each time,...

how to write into a text file by C program

my problem is fprintf is only printing part of the expected output into the file.When i use printf the output is correctly printed on the output window, showing that the loop is correct but when i use it with fprintf the complete output is not printed.Only the initial part is printed. PLease advise as to what might possibly be the pro...

How does fprintf in c++ work?

how does fprintf works?? if i write fprintf(outfile, "test %d %d 255/r", 255, 255); what does it mean?? i know outfile, is the name my of output file. what would the other values mean? ...

fprintf question

I am not asking how to do file I/O, its just more of a formatting question. I need to write a variable number of characters to a file. For example, lets say I want to print 3 characters. "TO" would print "TO" to a file. "LongString of Characters" would print "Lon" to a file. How can I do this? (the number of characters is defined in ano...

Malloc/Bus error with fprintf

Hi I am getting a malloc error with bus error on using the fprintf statements in C++ (code below). Any pointers on what could be going wrong? Note absAmb and dModel both have valid values. Thanks. FILE *fPtr; char fName[100]; sprintf(fName, "Info.dat", block); if ( (fPtr = fopen(fName,"w")) == NULL ) { return( FALSE ); } int ab...

Creating a FILE * stream that results in a string

I'm looking for a way to pass in a FILE * to some function so that the function can write to it with fprintf. This is easy if I want the output to turn up in an actual file on disk, say. But what I'd like instead is to get all the output as a string (char *). The kind of API I'd like is: /** Create a FILE object that will direct writ...

sending formatted messages across TCP connection

I have an existing C program which prints a number of messages to standard error using: fprintf(stderr, ... I would like to modify this program so that these messages are also sent out over a TCP connection across the Internet. (Which I have already created as a SOCK_STREAM socket.) What's the best way format the messages like they wo...

writing a replacement for a function which takes a variable number of parameters (c programming)

I'm looking to write a function to replace fprintf int fprintf ( FILE * stream, const char * format, ... ); I'm not sure how to define a function such as this, because, after the format parameter, this function takes a variable number of parameters. Specifically, it takes at least as many additional arguments as were specified in the ...

Problem writing array of doubles to a file

i have a really big array of numbers with double precision...i tried to write it into a file using fprintf()...i need to write these numbers one in each line so i have done something like this. if((fp2 = fopen("temp", "w")) == NULL) { perror("File cannot be opened"); exit(1); } for(int k = 0; k < j; k++ ) { fprintf(fp2, "%0.3lf\n", dif...

fprintf with string argument

Dear all, In order to creation a formatted file, I want to utilize fprintf. it must get char* but I have several string variables. Can anyone help me, please? Thanks ...

Is %dn a format string ?

Hi , I recently came across this line in a code - fprintf(logfile," |-IP Version : %dn",(unsigned int)iph->version); Is "%dn" here a format string ? If so , what does it signify ? ...

on mac osx, is fprintf thread safe?

If so, where is this documented? Thanks! ...

Question: Output two digits after decimal separator

Using fprintf, what is the format-string to output two digits after a decimal separator? float number = 3.0; fprintf(pFile, "%10.02f", number); This always outputs 3 instead of 3.00 How do I fill up the digits after decimal separator with zeros? I want 3.00 written in the output file. ...

why does fprintf doesn't work after fscanf?

Hello, I want to open a file for both writing and reading, but after I read from it I can't write: f_prefs = fopen(prefs_path, "r+"); while (fscanf(f_prefs, "%[^\n]\n", line) == 1) { ... do some stuff ... fprintf(f_prefs, "test"); // doesn't work ... } Any ideas? ...

.dat file, when created using Matlab, not opening

I am creating a .dat file with headers and data in Matlab like this: %# Define the name of the file where data is to be written dataName = 'sampledata_models_poro_reference_truth'; %# open the file fid = fopen('sampledata_models_poro_reference_truth.dat','w'); %# start writing. First line: title fprintf(fid,'%s\n',dataName); %# don't ...

a single C function to write data as text or binary

Hi all, I have a C function that writes some data to a text file. The data consists of floats, ints and strings. it looks something like this: writeAsTextFile( mystruct_t* myStructWithIntsFloatsAndStrings , const char* fileName); for doing this I use calls to fprintf; Now I would like to write the same data but as binary. I could...

Strange SEGFAULTS using fprintf

I'm having a very tough time debugging a multi-threaded C application that I've made a few changes to. I've been unable to use GDB to help identify the issue(see below code for more info). The following code is from one of the tasks that is opened in its own thread. I've snipped out most of the code following the problem. void tskPr...