Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   How to read the data line by line from a File? (http://www.go4expert.com/forums/read-data-line-line-file-t7783/)

Shilpa1 10Dec2007 11:32

How to read the data line by line from a File?
 
In my application,in Dialog1 writing the data line by line,upto this working perfectly,where as in Dialog2 while reading the data line by line always reading the first line.
How to read the data line by line?Though simple one,Iam in confusion.Pls help me.

In Dialog1, for File.txt ,writing the names as

Name1
Name2
Name3

and on the other side I want to read the names one by one,but In Dialog2 always reading the Name1,not going to the second line.

In Dialog1

Quote:

unsigned char* data[100];
//Open a File and write the data
FILE *pFile;
pFile = fopen ("File.txt","w+t");
for(TInt i=0;i<10;i++)
{
if(pFile!=NULL)
{
//write the data to File
fscanf(pFile,"%s\r\n",data);
fprintf(pFile,"%s\r\n",data);
}
}
In Dialog2

Quote:

//Open a File and read the data
FILE *pFile;
pFile = fopen ("File.txt","r+t");
for(TInt i=0;i<10;i++)
{
if(pFile!=NULL)
{
fscanf(pFile,"%s\r\n",data);
}
}

Shilpa1 10Dec2007 14:56

Re: How to read the data line by line from a File?
 
Hai,
pls see the File.txt.In Dialog1 Iam encrypting the data and writing the encrypted data to File.In Dialog2, I want to read the encrypted data from File one by one.Is this correct way of writing encrypted data to a File or Is it better to encode the encrypted data?If anybody having the sample code for Encoding/Decoding pls post it.

Salem 10Dec2007 17:47

Re: How to read the data line by line from a File?
 
1. Use [code][/code] tags when posting code.

2. Why are you trying to read and write to the file at the same time?

shabbir 10Dec2007 18:13

Re: How to read the data line by line from a File?
 
Please try to post instead of giving it as an attachment. I have removed the attachment from the post.

Shilpa1 10Dec2007 18:48

Re: How to read the data line by line from a File?
 
In File.txt Iam writing the following encrypted text.Now,I want to read the encrypted data line by line.How to do this?Pls help me.

Quote:

1v~/V,w0Kx'4ỲA2p &%`

RǕuVK561TlJB(
8,
Ť\j "Noφ{X_oԘyF
Mh7WGM V'G

bxʘ|9!6*K>|bKTI
Mh7WGM V'G


Salem 10Dec2007 21:26

Re: How to read the data line by line from a File?
 
Encrypted by whom, using what algorithm and with what key?

Good algorithms will destroy any sense of the idea of "lines" in the file and present you with a stream of what looks like random bytes.

Shilpa1 10Dec2007 22:47

Re: How to read the data line by line from a File?
 
Hai,
My major problem is how to read the data line by line from a File?Pls gave me an idea.

Salem 10Dec2007 23:18

Re: How to read the data line by line from a File?
 
Well if it's encrypted you have two choices
- fgetc, to read the file one byte at a time
- fread, to read a whole block of bytes at a time.

Having read some bytes, you then need to decrypt them in order to work out what the real data is, and where the lines are.


All times are GMT +5.5. The time now is 22:12.