473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Writing a file and appending the text

2
This is my first time using C and my first time posting so experts out there please be patient with me. I'm trying to write a file starting with one line and then append text to that file.
So far the only code that has been able to even produce the file is as follows:

char *szTestFile;
HANDLE hTestFile;
char szirdCreateFile[16];
unsigned uBytes;

Console Init( );
cls( );

szTestfile = "c:\\TestFile.txt";
hTestFile = CreateFile(szTestFile.GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
sprintf (szirdCreateFile; "TestLine"); //call this line "line 1"
WriteFile(hTestFile, szirdCreateFile, sizeof(szirdCreateFile)-1, &uBytes, 0); //"line 2"
sprintf (szirdCreateFile; "2ndTestLine"); //"line 3"
WriteFile(hTestFile, szirdCreateFile, sizeof(szirdCreateFile)-1, &uBytes, 0); //"line 4"

When I run the program, it's like the two lines mesh together on the same line and create some unintelligible characters. When lines 1 and 2 are commented out "2ndTestLine" appears in the file and when lines 3 and 4 are commented out "TestLine" appears in the file. My goal is to get "2ndTestLine" to appear on the line beneath "TestLine." PLEASE HELP!!!
Jul 12 '07 #1
5 1420
weaknessforcats
9,208 Expert Mod 8TB
It's going to help if you put the \n newline in the data being written. This is the separatpr between the lihes of text:

Expand|Select|Wrap|Line Numbers
  1. sprintf (szirdCreateFile; "TestLine\n"); //call this line "line 1"
  2.  
The number of bytes to write is the number of characters in the string:

Expand|Select|Wrap|Line Numbers
  1. WriteFile(hTestFile, szirdCreateFile, strlen(szirdCreateFile), &uBytes, 0); //"line 2"
  2.  
Jul 13 '07 #2
JosAH
11,448 Expert 8TB
I sincerely *hate* that Hungarian notation stuff; C looked much better before
Microsoft invented that terrible mishap.

kind regards,

Jos
Jul 13 '07 #3
Silent1Mezzo
208 100+
I sincerely *hate* that Hungarian notation stuff; C looked much better before
Microsoft invented that terrible mishap.

kind regards,

Jos
Wow I'd never even heard about Hungarian notation.... I just read up on it and found this
Hungarian notation can be used to reduce variable ambiguity and increase code clarity.
But to me it just makes variable ambiguity greater as well as convolutes the code more.
Jul 13 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
Quote:
Originally Posted by JosAH
I sincerely *hate* that Hungarian notation stuff; C looked much better before
Microsoft invented that terrible mishap.

kind regards,

Jos


Wow I'd never even heard about Hungarian notation.... I just read up on it and found this
Quote:
Originally Posted by
Hungarian notation can be used to reduce variable ambiguity and increase code clarity.

But to me it just makes variable ambiguity greater as well as convolutes the code more.
You have to look at the historical perspective: Only C. Multiple files. No way to find a variable unless you check 5000 header files. C programmers a into naming conventions in a big way.

Unfortunately, naming conventions don't work. The compiler can't verify you are using the convention. Just look a Microsoft code and you will see that no one ever followed the conventions anyway.

This Hungarion Notation was the brainchild of Charles Semonyi, who was Hungarian. (Yes, the same Charles Semonyi that just went into space as a tourist). Probably, he had a highTrip (hope-I-get-home-Trip) :)
Jul 13 '07 #5
JosAH
11,448 Expert 8TB
The trouble with that Hungarian notation crap is not just a naming convention
burden; it tries to encode the type of the variable in the variable name itself,
like 'lpszhfName' or something similar silly.

Changing the type of that variable turns into a day job that way. e.g. Eclipse
can find variable references, their types etc. and can change them for you on
the fly; there's no need for all that Hungarian notation hulla baloo.

adjKind plrnounRegards,

pronounJos
Jul 13 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Neil Trigger | last post by:
Is there a way of creating a seperate text file on a server every time a form is sent? -- ¿ Trigger ? http://www.magic2k.com/ http://www.oddmap.co.uk
2
by: caro | last post by:
Hi I am trying to write two Select * statements to the same text file using bcp (from a stored procedure). But cannot find a way of appending to a file using bcp. Does anyone know if this...
4
by: Thierry Lam | last post by:
Let's say I already wrote a file and have the following: testing testing testing testing testing testing Is there an easy way to write something of variable length at the top of the file? ...
16
by: Michael | last post by:
I have a data application in a2k that I need to create two fixed width text files and then combine them to a single file The first file is header information and the second is transaction data. ...
8
by: John | last post by:
Hi I am trying to set-up an app log file that needs to be created if does not exists but opened for append if exists. How does one go about doing this? ..net seems to have many ways to do io...
3
by: =?Utf-8?B?am9obmFicmFoYW0xMDE=?= | last post by:
hello all, I've already posted a thread with the same problem but couldn't satisfactory answer. Let's come to the point. I can write some text to a text file with WriteAllText method. How can I...
2
by: sarada purkait | last post by:
hii i have to write into a file from the start and then go on appending to it .. i tried using ( ios::out|ios::app) but by this the file keeps on appending every time i run the program and the...
3
by: sylvaticus | last post by:
Hello, is it possible to append some data on a text output file appending the data to each row, and without use too much computational I/O ?? Instead of the classical way: VARX VARY ...
6
by: Shawn | last post by:
Hello: I have the following code in a PHP file. An HTML form passes user comment data to the PHP, which then appends the user comments to the end of the HTML file on which the form is located....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.