LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-17-2008, 01:12 AM   #1
jaepi
Member
 
Registered: Apr 2007
Location: Urban Jungle
Distribution: Ubuntu
Posts: 189
Blog Entries: 1

Rep: Reputation: 30
text files contents


Hello there, I created a text file of 4gb in which the contents are all spaces. Now I created program that uses fread for me to look inside the files, when I printed the buffer, I saw a different character which is not a space. Why is it that there is a different character?
 
Old 06-17-2008, 01:22 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Perhaps it's an end-of-line character or something? Where is it in the file? What character does it appear as? Is there only one?
 
Old 06-17-2008, 02:28 AM   #3
jaepi
Member
 
Registered: Apr 2007
Location: Urban Jungle
Distribution: Ubuntu
Posts: 189

Original Poster
Blog Entries: 1

Rep: Reputation: 30
it appears as the first character, I casted it to unsigned short so it gives me a number. The rest is the same value and the last one is different because of the end of line or null terminating or whatever that is. I was thinking that it could be a header for the text file. Is this possible?
 
Old 06-17-2008, 03:36 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by jaepi View Post
The rest is the same value and the last one is different because of the end of line or null terminating or whatever that is.
Please provide some more information on how you made that big file full of spaces and please show the code that fread()s it. Also I think it is a good idea to make sure you know what a "null terminating" is when doing this kind of coding...


Quote:
I was thinking that it could be a header for the text file. Is this possible?
Normally not.
 
Old 06-17-2008, 04:08 AM   #5
jaepi
Member
 
Registered: Apr 2007
Location: Urban Jungle
Distribution: Ubuntu
Posts: 189

Original Poster
Blog Entries: 1

Rep: Reputation: 30
i have a software that can create text files in any size you want but produces only spaces.
 
Old 06-18-2008, 10:07 AM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by jaepi View Post
i have a software that can create text files in any size you want but produces only spaces.
yeah, its called fprintf

amways try something like:
Code:
#include "stdio.h"

main(int argc, char *argv[])
{
 int c;
 FILE * fstream;

 fstream = fopen(argv[1], "r");
printf("fstream =  %d\n", fstream);
 c = fgetc(fstream);

 while(c != EOF)
 {
  printf("%d\n", c);
  c = fgetc(fstream);
 }
 fclose(fstream);
}
and compare the decimal output to an ascii table. should be 32 for a space and the last byte is 0 for end-of-file.

season to taste.

Last edited by schneidz; 06-18-2008 at 10:14 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert DOS text files to UNIX text files ta0kira Linux - Software 7 03-15-2011 11:42 AM
sendmail : How to email contents of a text file? concoran Linux - Newbie 5 03-09-2008 08:27 PM
cutting down contents of text file kam_kenneth Linux - Newbie 2 05-22-2004 01:16 AM
tar from contents of a text file trpn Linux - General 3 03-08-2004 01:05 AM
How to read and change the contents of a text file? Bassam Linux - General 11 02-26-2004 04:08 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration