473,322 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

seek and fgets and fputs fopen

In c is it possible to open a file for read write and without using a buffer
or second file change one character in the file and close it modified form

ex.
status.txt contains:
This is mode 1.

change to

This is mode 3
Nov 1 '06 #1
4 6313
dave wrote:
In c is it possible to open a file for read write and without using a buffer
or second file change one character in the file and close it modified form
see:

std::ostream::seekp
std::ostream::write
Nov 1 '06 #2

dave wrote in message ...
>In c is it possible to open a file for read write and without using a buffer
or second file change one character in the file and close it modified form

ex.
status.txt contains:
This is mode 1.

change to

This is mode 3

std::fstream Zstat("status.txt", std::ios::out | std::ios::binary);
Zstat.seekp( 13 );
if( not Zstat ){
using std::cout; // for NG posting
cout<<" file error="<<Zstat.flags()<<std::endl;
cout<<" ios::good="<<Zstat.good()<<std::endl;
cout<<" ios::bad="<<Zstat.bad()<<std::endl;
cout<<" ios::eof="<<Zstat.eof()<<std::endl;
cout<<" ios::fail="<<Zstat.fail()<<std::endl;
}
else{
Zstat << "3";
}

--
Bob R
POVrookie
Nov 2 '06 #3

"BobR" <Re***********@worldnet.att.netwrote in message
news:NB********************@bgtnsc04-news.ops.worldnet.att.net...
>
dave wrote in message ...
In c is it possible to open a file for read write and without using a
buffer
or second file change one character in the file and close it modified
form

ex.
status.txt contains:
This is mode 1.

change to

This is mode 3


std::fstream Zstat("status.txt", std::ios::out | std::ios::binary);
Zstat.seekp( 13 );
if( not Zstat ){
using std::cout; // for NG posting
cout<<" file error="<<Zstat.flags()<<std::endl;
cout<<" ios::good="<<Zstat.good()<<std::endl;
cout<<" ios::bad="<<Zstat.bad()<<std::endl;
cout<<" ios::eof="<<Zstat.eof()<<std::endl;
cout<<" ios::fail="<<Zstat.fail()<<std::endl;
}
else{
Zstat << "3";
}

--
Bob R
POVrookie

how bout using fopen with *FILE and fputs
Nov 2 '06 #4

dave wrote in message ...
>
how bout using fopen with *FILE and fputs
Why, when you have std::fstream?

std::ifstream Ping("Some.png", std::ios_base::binary );
std::vector<unsigned charImage;
char In(0);
while( Ping.get( In ) ){
Image.push_back( static_cast<unsigned char>( In ) );
}
std::cout<<"\n Image.size() = "<<Image.size()<<" bytes."<<std::endl;

--
Bob R
POVrookie
Nov 2 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Adam Bergman | last post by:
Okay, I am working on a credit card validation script, I have it working perfectly (saving the return information from the server to a variable and echoing it for now) other than this weird error...
5
by: akins.steve | last post by:
Is it possible to write a function that uses stdout for both output and input? What I mean to say is, I can obviously write a line to stdout to ask for input, ie: fprintf(stdout, "%s\n",...
4
by: Karthick S. | last post by:
Hi, fgets returns NULL on error and the first argument on success. I want to open a file and read it using fgets. This is returning NULL, when the file is empty. Is there anyway to circumvent...
9
by: uidzer0 | last post by:
Hey everyone, Taken the following code; is there a "proper" or dynamic way to allocate the length of line? #include <stdio.h> #include <errno.h> int main(int argc, char **argv) { FILE *fp;
24
by: allpervasive | last post by:
hi all, this is reddy, a beginner to c lang,,here i have some problems in reading and modifying the contents of a file,, hope you can help to solve this problem. Here i attach the file to be...
285
by: Sheth Raxit | last post by:
Machine 1 : bash-3.00$ uname -a SunOS <hostname5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R bash-3.00$ gcc -v Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/...
2
by: stirfie | last post by:
I am having trouble with the following script:- <?php //function to send back to view function post($host, $path, $data) { $http_response = ''; $content_length = strlen($data); $fp =...
3
by: FireHead | last post by:
Hello comp.lang.c Couple of years ago I created a topic as to how I can use the function fgets so that I can read a line of text from a source of data. After a long time I have finally got all...
14
by: blindsey | last post by:
Trying to use c for the first time in years and blowing out in fgets. I created this very simple program which still produces the error: #include <stdio.h> int main(int argc, char *argv) {...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.