473,786 Members | 2,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 characterreadin g
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 2056
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 characterreadin g
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.progr ammer for system-specific information.
and the second is that I couldn't find a characterreadin g
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 characterreadin g
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
2105
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. I strongly named my control assembly . I created a machine level permission set, and assigned FileDialog, FileIO and User interface permission. I created a code group under all_Code, associated my assembly's strong name to that group and...
0
950
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 would have created a user- defined data structure to store my data from which I could load / save to a Random Access Text File via textboxes etc on the form. However the problem I'm now facing is twofold. firstly:
5
8631
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". Same file path containing special characters works fine in one machine, but doesn't work in other. I am using following API function to get short file path. Declare Auto Function GetShortPathName Lib "kernel32" (ByVal lpszLongPath As
8
4203
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 __construct($filename = null, $mode = 'r+'){
3
2240
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 grant the permission? Thanks, Marquis
13
4750
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 code: Public Function IsValidName(ByVal name As String) As Boolean Dim i As Integer For i = 0 To name.Length - 1 Dim ch As Char = name.Chars(i) Dim uc As Globalization.UnicodeCategory =
0
2033
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 location..?
1
2593
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. I want to stop/cancel the file io operation and return back to the calling form.
0
180
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
9492
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10108
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9960
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6744
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.