- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: C++ fgets issue
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2009 03:59 AM
09-17-2009 03:59 AM
C++ fgets issue
fgets( line, BUFFER,fp );
\1\Tommy\Smith1\23\0\985\302\\
\2\John1\Boling1\24\0\986\304\\
\3\Value1\Poulos1\25\1\987\305\\
Now if I have same data,
\1\Tommy\Smith1\23\0\985\302\\
\2\John1\Boling1\24
\0\986\304\\
\3\Value1\RamS\25\1\987\105\\
if I use fgets it return me for second record, "\2\John1\Boling1\24", in fact it should return me "\2\John1\Boling1\24\0\986\304\", it should trip all the blank space. How can i do this in C++.
- Tags:
- fgets
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2009 05:08 AM
09-17-2009 05:08 AM
Re: C++ fgets issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2009 01:40 AM
09-18-2009 01:40 AM
Re: C++ fgets issue
\2\John1\Boling1\24
\0\986\304\\
How is this the same? Is the line is split with a newline?? Or did the forums mess up on spaces?
>in fact it should return me "\2\John1\Boling1\24\0\986\304\", it should strip all the blank space.
How do you know there are blanks? We can't see them. You need to better describe how those two record fragments are separated.
Or attach an example file.
>How can I do this in C++?
You might was well do it in C or C-like code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2009 02:18 AM
09-18-2009 02:18 AM
Re: C++ fgets issue
assigned points to 5 of 18 responses
http://forums.itrc.hp.com/service/forums/pageList.do?userId=CA1420119&listType=unassigned&forumId=1
You need to correct this oversight.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2009 03:49 AM
09-18-2009 03:49 AM
Re: C++ fgets issue
First of all fgets doens't strip blank.
It seems that \2\John1\Boling1\24 and
\0\986\304\\ are two different lines separated by newline character.
Assuming that "\\" is the mark of end of your logical record, you need to test that you received all information before use it.
So I suggest this following lines :
char *pt = fgets( line, BUFFER,fp );
int len = strlen(*pt);
if (line[len-1] != '\' && line[len-2] != '\') {
fgets(line+len, BUFFER - len, fp);
}
The idea is to fill up line with the next record to merge the info. Be carefull if you last record has not these double backspaces. You should handle this error with errno !
Regards,
Roland