LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   text files contents (https://www.linuxquestions.org/questions/programming-9/text-files-contents-649804/)

jaepi 06-17-2008 01:12 AM

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?

David the H. 06-17-2008 01:22 AM

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?

jaepi 06-17-2008 02:28 AM

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?

Hko 06-17-2008 03:36 AM

Quote:

Originally Posted by jaepi (Post 3187063)
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.

jaepi 06-17-2008 04:08 AM

i have a software that can create text files in any size you want but produces only spaces.

schneidz 06-18-2008 10:07 AM

Quote:

Originally Posted by jaepi (Post 3187148)
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.


All times are GMT -5. The time now is 02:23 PM.