473,473 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

insert title string into a file

Hi,
I would like to replace title string into a file. My output file looks like
this:

Name Age Address
==== === ======
Ken 23 New York City
Rebecca 25 Toronto

The data list will be appended. But I only want the title string appear once
at the top only:
Name Age Address
==== === ======

I think each time I append the data, i will replace the same string title
for the 1st and 2 nd line. or you have better idea ?

FILE *fptr;
char fileName[40];

// open file.
if ((fptr = fopen("text.txt", "aw"))== NULL)
{
printf("Error: Couldn't create file.\n");
exit(1);
}

// replace the 1st and 2nd line string title each time append.

// append into file
fprintf(fptr, "%s %s %s ", name, age, address );
fprintf(fptr, "\r\n");
fclose(fptr);
Thanks.

Dimension.
Nov 14 '05 #1
1 1965
Magix wrote on 27/07/04 :
I would like to replace title string into a file. My output file looks like
this:

Name Age Address
==== === ======
Ken 23 New York City
Rebecca 25 Toronto

The data list will be appended. But I only want the title string appear once
at the top only:
Name Age Address
==== === ======

I think each time I append the data, i will replace the same string title
for the 1st and 2 nd line. or you have better idea ?
I'm not sure I undestand what you mean.

Sounds to be a design question, but the 'tile' lines are only
interesting in some 'output report'. They don't need to be stored, but
it doesn't harm...

Let's see the code.
FILE *fptr;
char fileName[40];

// open file.
if ((fptr = fopen("text.txt", "aw"))== NULL)
This invokes an undefined behaviour. You must choose between "w"
(create) or "a" (append).
{
printf("Error: Couldn't create file.\n");
exit(1);
}

// replace the 1st and 2nd line string title each time append.
There is nothing like 'replace' concerning streams. It's 'write'
(create a new file) of 'append' (add to an existent file or create it
if new).
// append into file
fprintf(fptr, "%s %s %s ", name, age, address );
fprintf(fptr, "\r\n");
You want one line:

fprintf (fptr, "%s %s %s\n", name, age, address);

Design issue : note that blank separated fields can be tricky if you
have a datum with blank (an address, for example). A more solid format
might be used, like fixed field width or comma separated fields (CSV).
fclose(fptr);


--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html

"C is a sharp tool"

Nov 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tim::.. | last post by:
Can someone please help! I'm trying to write an insert statement for a complex datagrid! The database consists of the following data structure! ..tblContent PageID PK ModDate Description...
2
by: Tim::.. | last post by:
Can someone please tell me why I keep getting the following error from the code below! Error: INSERT statement conflicted with COLUMN FOREIGN KEY constraint...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
1
by: Ed Dror | last post by:
Hi there, I have ASP <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Guestbook.aspx.vb" Inherits="Guestbook" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
0
ak1dnar
by: ak1dnar | last post by:
There is a Error getting while i am entering records using this jsp file. <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %> <%@ include...
0
by: Michael | last post by:
I know I am missing something simple, but I am stuck. When I submit the following for the employee info gets stored in scale1 and scale1 shows the employee number. Can someone show me my...
5
by: =?Utf-8?B?VEQgaXMgUFNQ?= | last post by:
I have a FileUpload control within a FormView (although I tried it outside the FormView and got the same result) in the InsertTemplate. When the <Insertbutton is clicked and the Insert Command is...
2
by: franc sutherland | last post by:
Hello, I am using Access 2003. Is it possible to use string variables in the INSERT INTO statement? I am using the INSERT INTO statement to add a long list of contacts to a group by looping...
2
by: vijaykumardahiya | last post by:
Hello Sir, I have a simple Issue but It is not resolve by me i.e input parameter are not store in Ms-Access. I store the input parameter through Standard Action <jsp:useBean>. jsp:useBean call a...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.