user980468
user980468

Reputation: 3

remove newline characters from text file while writing data

I am getting a newline character into a text file while I was writing some content into the text file using the code below

sprintf(str,"GodownName,LorryNumber,InvoiceNumber,CementCompanyName,RcvdPrsnName,RcvdPrsNDsgnation,EntityQty,Date\0");
write(fd,str,strlen(str));

the text is writing from 2nd row and an unwanted newline is writing at 1st row. I want my text to be written from 1st row. So please any one help me to remove newline characters or spaces from text file

Thanks in advance

Upvotes: 0

Views: 417

Answers (2)

wormsparty
wormsparty

Reputation: 2499

My guess is that you have another function which writes in fd before the call of this function.

Besides, writing "\0" at the end of a string litteral is useless, there's already one.

Upvotes: 2

Ed Heal
Ed Heal

Reputation: 59997

You do not need the \0 at the end. Is str long enough? If not that could cause the problem that you are encountering.

Upvotes: 0

Related Questions