read an ascii file with fopen

I try to open with fopen and read an ascii file, line by line, but get
garbage - among the right data in the CString variable that is filled with
this line data.

Can someone copy&paste the right code how to so that?

Thanks in advance.

Mark


0
mark5578 (1)
5/29/2006 3:05:38 AM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
705 Views

Similar Articles

[PageSpeed] 56

"Mark" <mark@chasan.ar> wrote in message
news:%23sPmEzsgGHA.2208@TK2MSFTNGP05.phx.gbl...
> I try to open with fopen and read an ascii file, line by line, but get
> garbage - among the right data in the CString variable that is filled
with
> this line data.
>
> Can someone copy&paste the right code how to so that?
>
> Thanks in advance.
>
> Mark
>
>

When opening the file you need to have a buffer large enough to hold the
string plus the null. How you open the file is important too. MSDN lists
all the open flags for _fopen. The _fopen() function has versions for
defining unicode and multibyte as well.

// ---------------------------------------
// assuming the function returns boolean

    FILE *fh;            // file handle
    char sBuffer[255];   // buffer
    CString sLine;       // CString var

    if((fh=fopen(szFilename, "rb"))==NULL)    // (r+, r, a, a+, b etc.)
    {
        return FALSE; // return failure
    }

    // loop with EOF and error checking
    while(!feof(fh) && !ferror(fh))
    {
        fgets(sBuffer, 255, fh);    // read string into buffer
        sLine = sBuffer;            // CString now holds string
        sBuffer[0] = '\0';          // clear buffer
        // do something useful with CString here
    }

    fclose(fh);    // close handle
    return TRUE;   // return success
// ---------------------------------------

Also take a look at CStdioFile class and CStdioFile::ReadString()
function in the MSDN Library. One version of ReadString stores the
newline char and the other does not.

HTH
Mark F






0
5/29/2006 7:28:55 PM
Reply:

Similar Artilces:

Reading .wks file
Greetings...according to the Excel "help" file, as well as the file extension listing, I *should* be able to read an *.wks file, but Excel insists that it cannot. I am pretty sure the file was created in Microsoft Works. Is there a converter somewhere that I can download/install? Cheers - S2 Excel can read Works 2.0, not later. You have to save them in Works as excel files or Works 2.0 or get a commercial converter. -- Regards, Peo Sjoblom "Skip Stocks" <anonymous@discussions.microsoft.com> wrote in message news:AFC110E0-641D-4D87-9464-B930CC41CF02@microsoft....

Inserting text from a .txt file
I'm trying really hard to jump on the bandwagon and migrate from Outlook Express to Outlook, but the more I try, the more frustrated I get. Anyway, here is my question: How do I insert the text from a text file into my e-mail document. I am using the rtf editor. thank you, ~alan copy/paste? "~~Alan~~" <alan.shepro_NOSPAM@verizon.net> wrote in message news:%23%23AwZrIKEHA.1264@TK2MSFTNGP12.phx.gbl... > I'm trying really hard to jump on the bandwagon and migrate from Outlook > Express to Outlook, but the more I try, the more frustrated I get. > > Anywa...

xml config file...
hello, I ve a Windowsapplication with a configuration file app.config... (it's in xml) code app.config: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name = "MyNameValueSection" type="System.Configuration.NameValueSectionHandler" /> </configSections> <MyNameValueSection> <add key="MyKey" value="MyValue" /> </MyNameValueSection> <appSettings> <add key="test" value="MeinInhalt" /> </appSettings> </configurati...

Import txt file into excel with 281,344 rows
Hi, I've got a very large txt file that I need to import into excel. It has 288,344 rows. Is there a way I can do this? The fields on my txt file are separated by a pipe "|" Thanks in advance. If you're using xl2007, then that data will fit. Open the .txt file and choose delimited by | If you're using xl2003 and below, you could use your favorite text editor to make several smaller .txt files (65536 rows or smaller) and import each into separate worksheets. JulieM39 wrote: > > Hi, I've got a very large txt file that I need to impo...

error attaching file to email
Getting the error: File Upload Failure There was a problem while attempting to upload the requested file. Check the path and try again. The file is a pdf, about 74 KB. Any ideas?? ...

path of .pst file
Hello everyone, I want to develop a stand alone application to send and recieve mails through MS Outlook.how can i retrieve the path of .pst file from .net application. actually i am thinking of reading the pst file of MS Outlook. is it possible? Thanks in Advance jyoti The pst file is stored in the profile path of the MSOUTLOK Since the path of the pst can be varied by the user, as can its name, ie it neednt be in the install default path, your app would first have to search for the pst, then you would have to figure out if it/which was the current pst. There are alleged to be third ...

Weird files
Just noticed I've got a ton of weird files with names like 2BE48300. The normal files seem to be ok. Any idea what might be producing all these extra files? -- For a list of all the ways technology has failed to improve the quality of life, please press three. ....Alice Kahn Not sure. Perhaps cleaning up your hard drive will help. http://www.officearticles.com/misc/how_to_clean_up_your_hard_drive.htm Are they Excel files? **************************** Hope it helps! Anne Troy www.OfficeArticles.com **************************** "Steve" <teu@qprc.inv> wrote in message...

File won't open as read only
I have a file that is in use, but another person opens it and it doeasn't display the "file is in use" message. Is there a setting or fix? Hi have you shared this file? -- Regards Frank Kabel Frankfurt, Germany John wrote: > I have a file that is in use, but another person opens it > and it doeasn't display the "file is in use" message. Is > there a setting or fix? The file is on a network share. The share has all the appropriate permissions. >-----Original Message----- >Hi >have you shared this file? > >-- >Regards >Frank Ka...

"File access denied" to PST file
I have gone from Windows 2000 running Outlook 2000 to Windows XP Pro running Outlook 2003. When I try opening my saved .pst file in the new Outlook I get a message saying "File access denied. You do not have permission required to access to file mailbox.pst" I am logged on as Administrator, as I was on the old install. How do I open my saved mailbox.pst or archive.pst? TIA How did you try opening it? is this a local .pst file? If it is not on your C: drive, is it marked Read-Only? --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion int...

Make excel 2003 default to open files
I have Excel 2003 running alongside 2007. Double clicking an excel file causes it to open in 2007; how do I force 2003 to open the files instead? Sandy You most likely have to reset your file association from 2007 to 2003. Close Excel first and On the Windows Taskbar 1) Start>Run "excel.exe /unregserver"(no quotes)>OK. 2) Start>Run "excel.exe /regserver"(no quotes)>OK. See the space between exe and /regserver You might have to designate a full path to excel.exe for Office 2003 In that case Start>Run "C:\your path to\office11\excel.exe" ...

scrambled excel file
Hi AGAIN. I'm trying to open a file that was deleted and later retrieved through GetData Back. It has an .xls extension, but when I try to open it, it's just symbols. Is there some way I can retrieve the proper info. from that file? Do I have to save it as something else? I really need this file back - l mean life & death!! I will attach the file to see if someone can figure this out for me. Thanks again for your help. Your advice last time was great. Sandy Attachment filename: wolf_info liz.xls Download attachment: http://www.excelforum.com/attachment.ph...

Read mail arn't marked as read anymore
After an SP upgrade of my Office 2000 the priviewed mail doesnt get marked as read anymore. I have tried to change the time (Tools->Options->Priview pane) from 2 -> 3 -> 4 seconds but nothing works. The only way to mark a mail as read is either to open it or right click it and chose Mark as read. Since I only use the priview pane this is very anoying for me. Is this a bug or has some setting changed with the SP? ...

How to give other users read-only access to Calendar
I want to allow the group Everyone to have read-only access to a calendar in a certain mailbox. I can do this by granting the permission 'Full mailbox access' (under 'Mailbox rights', under 'Exchange Advanced', for the particular user). However this also allows people to to do everything (ie: they become read-write users). I notice that every mailbox in the system has 'Read permissions' granted to group Everyone. This does not allow other people to open items in the mailbox, but as I understand it, permits Exchange Server and Outlook to do shared meetin...

Delete oldest file first
All, I am looking for some code that deletes the oldest files first in a directory. Any help would be great. Thanks in advance. "karibbean" <sharp_mind@REMOVE.this.email.msn.dotcom> wrote in message news:uJZArpxvFHA.2132@TK2MSFTNGP15.phx.gbl... > I am looking for some code that deletes the oldest files first in a > directory. Any help would be great. Thanks in advance. See FindFirstFile, FindNextFile, FindClose, DeleteFile -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is ...

excel file can not be accessed
When opening an excel file I get an error that reads " 'Excel File Name.xls' cannot be accessed. The file may be read-only, or you may be trying to access a read-only location. Or, the server the document is stored on may not be responding." The file is not read-only. The other files in the same location are readable. The document is stored on a local drive. Any suggestions on how to read the file? Thanks for your time. Dave Could this be it? http://www.contextures.com/xlfaqApp.html#ReadOnly (from Debra Dalgleish's site) Dave wrote: > > When op...

Web page file name output
My client has a 100 page publisher document and I am trying to convert that to Web pages. It works BUT, the out put files file names that don't make sense. I end up with Page1152.htm, Page1351.htm, Page1390.htm and not page 1, 2, 3 etc that I would expect. I can't see any rhyme or reason to the page numbers that it outputs. I would have thought that it would use the emended page numbers within the document. Is there a way to make the Web output the pages Page1.htm, Page2.htm etc? Dan The bad new is that is the way both Publisher 2003 and 2007 work by design and default....and ...

open pst file?
I received an email on outlook and saved it to a file in my docs to review later. Now, I tried to open a pst file in the email and was given a message that there is no program available to open it, or something to that effect. I have gone to the office website--no info. I read the discussion postings here and the closest one seems to suggest a solution through explorer somehow. I am not versed in these issues. It would seem there would be a built-in solution for this but apparently not. I am stuck! You have to use your email client to import a PST file. Go to FILE>IMPORT AND E...

Close Outlook in Batch File
I have a batch file that backs up all the networked computers in the office to the server. This program will back up the Outlook (pst) file if the employee remembers to close Outlook. Is there a command line I can use in my batch program that will close Outlook? ...

Several files opening at the same time
I have a shortcut on my Quick Launch bar to a file called Index.xls wherein other hyperlinks take me to a zillion other places as a means of organisation of my computer data. For a couple of months I've been finding that whenever I click Index.xls another file called PERSONAL.XLS opens as well (or in fact momentarily before). I don't know why this is happening. As far as I know I did not change anything that might cause this phenomenon. I located PERSONAL.XLS and changed the filename to PERSONAL.XL1 to see if that might prevent it from opening, but now I have PERSONAL.XL1, PERSONA...

reading confirmation
Good day, I have a problem with outlook. When they send a message to me that demands the shipment of a reading confirmation, even if I accept, the reading confirmation does not come received from the sender. Someone knows from what depends and in which way I can resolve the problem? Thanks for the eventual answers. Niki In news:eht7fo$251$1@fata.cs.interbusiness.it, Niki <nicola.pantaleo@yahoo.it> typed: > Good day, > > I have a problem with outlook. When they send a message to me that > demands the shipment of a reading confirmation, even if I accept, the > read...

"Unblock" feature should be optional when reading e-mail in CRM
When viewing e-mail messages in CRM, a line appears saying "Unblock" to allow the full message content to be read. Can this be made a configurable server or security setting? We are trying to reduce "clicks" as much as possible. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agre...

File, Send, Message to Mail Recipient
Hi there. We use Sage line 50 and send mail via Outlook to recipients. This has stopped working. We've reinstalled Sage, reinstalled Office 2000, removed and reinstalled both and even installed office 2003 to try and get it working again. From Word, we can send to, but not Sage. Anyone have any ideas? Regards, Neal Blackie. Have you checked Sage's support? Integration with Office/Outlook is something that they would be responsible for, not Microsoft. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert latest v...

Cannot delete xml file - file based event scheduling
Hi, I have a report scheduled with File based event scheduling in CR XI Server version 11.5. The report is created with XML file as its datasource. The report will be triggered if the event of xml file is created in the source directory. As per the schedule, it will look for the event to occur every 1 minute. Since I need to enerate this report everytime the file comes into the directory, I have to delete the file after he report is generated, so that, next time the file comes in, the report will be generated again. After the report is run for the first time successfuly as the event occurs...

Previously used file option GONE? help please
Win98SE 'Office XP Pro' In Excel I am unable to find how to enable "open previosly used files" or words to that effect. I have checked in "options" but cannot see it there. When I used it previouly I was able to select the number of files last used, which would be available for me to select when starting EXCEL. TIA Hi do you mean the option in the 'File' menu (at the bottom)? -- Regards Frank Kabel Frankfurt, Germany Terry wrote: > Win98SE > 'Office XP Pro' > > In Excel I am unable to find how to enable "open previosly used...

The memory could not be "read".
I'm at work yesterday afternoon responding to e-mail on my desktop, and Adobe pops up from the toolbar with a notice that there is an update available for Acrobat. I accept the download, keep plugging away at my e-mail, and install it when it's done. It runs through the install, tells me that I should restart, but I ignore it and keep working. It's near the end of the day and I'm going to be going home soon anyways. I forgot to turn it off when I left. Came in this morning, restarted it through the Start menu, and rebooted. Upon reaching the "Ctrl+Alt+Del" ...