473,396 Members | 1,847 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,396 software developers and data experts.

How to find out file's text length

57
I want to see the file's text's length (How Many Letters).

How Can I Do That????
Jun 28 '06 #1
12 40481
Banfa
9,065 Expert Mod 8TB
If You are using MSVC

GetFileSize

Alternitively

Open the file - fopen
goto the end of the file - fseek
get the file position - ftell
close the file again - fclose
Jun 28 '06 #2
Kasya
57
:confused: I don't Understand.

???? :confused: :confused:
Jun 28 '06 #3
Banfa
9,065 Expert Mod 8TB
Those are functions you can look them up in the links I provide in one of your other posts.

If you are using WIN32, i.e. developing on the Windows platform for the Windows platform you can call

GetFileSize( ... )

if you are not on the Windows platform or need to write portable code then you can use the sequence of function calls

fopen( ... )
fseek( ... )
ftell( ... )
fclose( ... )

I suggest you go and look up the help of these functions.
Jun 28 '06 #4
Kasya
57
In My Document Its Lenght is 36 I Think but in there it writes 6

WHy???
Jun 28 '06 #5
D_C
293 100+
Is it referring to the number of lines, or the number of characters? Could you post the document, since it doesn't seem too big. I am assuming it's just a test file.
Jun 28 '06 #6
Banfa
9,065 Expert Mod 8TB
Also postring the actual code you have written would help if you wish us to solve any problems in it.
Jun 28 '06 #7
Kasya
57
Is it referring to the number of lines, or the number of characters? Could you post the document, since it doesn't seem too big. I am assuming it's just a test file.
YES - It is a Test File:

There I write 5 times "<Kasya>" word in tags
Jun 29 '06 #8
Kasya
57
Here is My Code:

using namespace std;
int main ()
{
char buffer[80];
FILE * pFile;
pFile = fopen ("size.txt","r+");

fseek (pFile,9,SEEK_SET);
cout << ftell(pFile);

fclose (pFile);
return 0;
}
kasya.byethost10.com/size.txt
Jun 29 '06 #9
Banfa
9,065 Expert Mod 8TB
Use [code&#93 and [/code] to encapsulate code

Expand|Select|Wrap|Line Numbers
  1. fseek (pFile,9,SEEK_SET);
  2.  
Your error is on this line, SEEK_SET sets the origin of the seek (reposition) to the start of the file so with your code the file pointer will always be positioned 9 bytes from the start and ftell should always return 9.

The other options are SEEK_CUR sets the origin as the current position of the file pointer, and SEEK_END set the origin as the end of the file so to position the file pointer at the end of the file so that ftell will give you the file size you should be using

Expand|Select|Wrap|Line Numbers
  1. fseek (pFile,0,SEEK_END);
  2.  
Also you are opening the file in "r+" mode, but you never write it, however opening the file in text mode can confuse things as end of line processing will happen. I subbest you use "rb" mode instead which is read only binary.

Cheers
Ben
Jun 29 '06 #10
Kasya
57
:) :) :) Thanks!!!!!!!!!!!!
Jun 29 '06 #11
Why not stick to the old faithful ? :

Expand|Select|Wrap|Line Numbers
  1. long FileSize(char* filename)
  2. {
  3.   struct stat stbuf;
  4.   stat(filename, &stbuf);
  5.   return stbuf.st_size;
  6. }
That's the method described in "The C Programming Language" is much simpler than any other technique, plus you get access to all this as well:

Expand|Select|Wrap|Line Numbers
  1. struct stat   /* inode information returned by stat */
  2.    {
  3.        dev_t     st_dev;      /* device of inode */
  4.        ino_t     st_ino;      /* inode number */
  5.        short     st_mode;     /* mode bits */
  6.        short     st_nlink;    /* number of links to file */
  7.        short     st_uid;      /* owners user id */
  8.        short     st_gid;      /* owners group id */
  9.        dev_t     st_rdev;     /* for special files */
  10.        off_t     st_size;     /* file size in characters */
  11.        time_t    st_atime;    /* time last accessed */
  12.        time_t    st_mtime;    /* time last modified */
  13.        time_t    st_ctime;    /* time originally created */
  14.    };
  15.  
Aug 20 '07 #12
This is exactly what i wanted now because I'm making a prime finder another thing I'd like is a loop to check all possible odd factors if I can do that i can find all primes under 18 quintillion I think and store them in files ( yes I have nearly 200 GB of space left)
Aug 14 '09 #13

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

Similar topics

1
by: wtnt | last post by:
Hello. I've searched all over and haven't seen another thread with this problem. Please bear with me as I try to explain. thanks. :) I have some programs that need to be cross-platform...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
3
by: Debbie Carter | last post by:
Can XML files be easily encrypted?
1
by: Jerry John | last post by:
I am working in ASP.NET with C#. I have a text file which contains datas with delimiters. For example:- MSH|^~\$|DISCHARGE|CLAY COUNTY MEMORIAL|||200502110939| I also have an XML file created...
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
4
by: Natalia | last post by:
Hello, I need to provide the ability to post file and some form elements via our website (asp.net) to the third party website (asp page). On http://aspalliance.com/236#Page4 - I found great...
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
9
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post by:
I want to open a text file and format it into a specific line and then apply color to a specific location of the text and then display it in a RichTextBox after all of this is done. I can do all...
1
by: amiparna | last post by:
There is two frame in my form.In d first frame there is a text box,and i give some word in the text box.I want to search the word from a file from the location(http://45.12.09.31...........) and if...
2
by: cleary1981 | last post by:
Hi, I have created a script in PHP thats generates an SVG image. Want I want to do is have PHP save this as example.svg. Can this be done? Heres my code <?php require "config.php"; $proj_id =...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...

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.