473,406 Members | 2,867 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,406 software developers and data experts.

function and fileio questions

I got some maybe stupid questions about file output and functions.
At first I have to say I'm programming on Linux.

The first thing is I couldn't find a function which can tell me
microseconds and the second is that I couldn't find a characterreading
unbuffered function.

Also I couldn't compare the cursorpositions in files.

And the last thing is that I couldn't insert text in a file(or delete
it) with the function fopen() and then using fprintf(). Either I
overwrote the hole file or I just attached the text to the end.

I hope you can help me.
Thanks in advance.

Nov 14 '05 #1
4 2031
Erik Paul wrote:

I got some maybe stupid questions about file output and functions.
At first I have to say I'm programming on Linux.
When it is necessary to mention the system you are using,
it is usually the case that the questions are about that system
and not about the C programming language. You will probably
get better answers from a newsgroup devoted to Linux, or to
Unix programming in general.
The first thing is I couldn't find a function which can tell me
microseconds [...]
Standard C provides time() to measure "real-world" time and
clock() to measure processor time. Standard C does not specify
the accuracy of these measurements, nor the precision of their
expression. For some non-Standard possibilities that might be
available on your system, see Question 19.37 of the comp.lang.c
Frequently Asked Questions (FAQ) list at

http://www.eskimo.com/~scs/C-faq/top.html
and the second is that I couldn't find a characterreading
unbuffered function.
This is Question 19.1.
Also I couldn't compare the cursorpositions in files.
I am not sure what you mean by "cursorposition." If you
mean the position at which the next read would start, ftell()
can provide this as a number -- but the number might not be
meaningful for a text stream.
And the last thing is that I couldn't insert text in a file(or delete
it) with the function fopen() and then using fprintf(). Either I
overwrote the hole file or I just attached the text to the end.


This seems to be Question 19.14, or possibly 19.13.

--
Er*********@sun.com
Nov 14 '05 #2
Erik Paul <In**************@freenet.de> writes:
I got some maybe stupid questions about file output and functions.
At first I have to say I'm programming on Linux.
That's a bad sign--if you have to say what platform you're using,
then the question is probably off-topic in comp.lang.c, because
we only discuss the standard C programming language here.
Extensions and system-specific features are off-topic.
The first thing is I couldn't find a function which can tell me
microseconds
If you mean "the current time in microseconds", there's nothing
in standard C that can portably tell you that. Try
comp.unix.programmer for system-specific information.
and the second is that I couldn't find a characterreading
unbuffered function.
You can use setvbuf() to turn off buffering for a file, then
getc() to read a character from it unbuffered. However, if you
mean "read a character from the user without waiting", see C FAQ
19.1. (Use Google to find the FAQ.)
Also I couldn't compare the cursorpositions in files.
In binary files, you can call ftell() to find out the current
number of characters from the beginning of the file. If ftell()
fails, as it might if you're at a position in the file that can't
be represented as a long int, it returns -1.
And the last thing is that I couldn't insert text in a file(or delete
it) with the function fopen() and then using fprintf(). Either I
overwrote the hole file or I just attached the text to the end.


See C FAQ 19.14.
--
"Some programming practices beg for errors;
this one is like calling an 800 number
and having errors delivered to your door."
--Steve McConnell
Nov 14 '05 #3
Erik Paul wrote:
The first thing is I couldn't find a function which can tell me
microseconds What do you mean? The seconds/microseconds which have passed?
and the second is that I couldn't find a characterreading
unbuffered function.

I don't know if ANSI C has functions for unbuffered I/O,
but since you are working on Linux you could use the POSIX functions
declared in fcntl.h.

http://www.opengroup.org/onlinepubs/...s/fcntl.h.html
http://www.opengroup.org/onlinepubs/...ions/open.html

For discussing this functions you should consult as POSIX newsgroup.

-Robert

--
Robert Bachmann _ _
Ro*************@rbdev.net |_) |_)
| \.|_).
Nov 14 '05 #4
On Mon, 15 Dec 2003 18:22:37 +0100, Erik Paul
<In**************@freenet.de> wrote:
The first thing is I couldn't find a function which can tell me
microseconds


When I want to time small functions or sections of code, I use an
assembler function that gets the Pentium or AMD processor's "time
stamp counter" into EDX;:EAX. The function, therefore, returns a
"long long" value. It's just "rdtst" followed by "ret". The function
itself requires 53-115 clocks to run, including the cost of assigning
the returned value to a variable. A microsecond counter isn't much
use except for pieces of code that take at least several microseconds
to run.

Nov 14 '05 #5

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

Similar topics

1
by: Moe | last post by:
I have a winForm control that contains an openFileDialog. I am using this control in a webForm by enbedding it using an <object> tag. I need to access some information about the file on the client....
0
by: Steven Smith | last post by:
Hi guy's I've hit a bit of a sticking point, I'm sure this is simple enough but I just can't get my head around it and I'm looking for a bit of direction. When dealing with FileIO up until now I...
5
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file"....
8
by: Cruella DeVille | last post by:
I'm writing a class to handle reading/writing from/to files like this (shortened) lass FileIO{ private $filename; private $mode; private $filePointer; private $dictionary; public function...
3
by: Marquis | last post by:
I am writing a ActiveX dll using Visual C# However , i am facing fileio and environment permission problem. Is there any way to solve this problem? just as signing the dll or other method to...
13
by: dgk | last post by:
I can't find anything in the framework that will tell me whether a filename is valid. I suppose that I can just try to open it and trap an error but that seems wasteful. I dug around and found this...
0
by: =?Utf-8?B?bWFnZWxsYW4=?= | last post by:
Hi All, I have the following: FileIO.FileSystem.CopyDirectory(strFromString, strLocString, FileIO.UIOption.AllDialogs) Q: How do I access the UI that is presented and re-positon the x,y...
1
by: =?Utf-8?B?bWFnZWxsYW4=?= | last post by:
hi all, I have a button (stopcopy) that I want the user to cancel out of a long file copying operation. I'm not clear what I should "adding" in the sub to make this happen besides & return....
0
by: Gary Herron | last post by:
Marlin Rowley wrote: You don't need the newsgroup to answer this kind of question. Just try it! abcdefghi abcd Notice that the index does not change the original array. Gary Herron
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.