473,796 Members | 2,591 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

success! I think

I began to think about some excercises I could with files after reading
turtorials today on arithmetic operators and confusing myself and decided to
do this.
Take the mv command from linux that moves and renames files read it as
binary and write it as text. After some compiler qipes it compiled and I
believe it did want I wanted it to.

#include <stdio.h>

int main(void) {
FILE *ifp, *ofp;
int a;
ifp=fopen("mv", "rb");
ofp=fopen("m"," wt");
a=fgetc(ifp);
if (a==EOF) {
fclose(ifp);
}
fputc(a,ofp);
if (a==EOF) {
fclose(ofp);
}
}

Because I didn't know how long the file would be I couldn't say exactly
how many bytes I should read so fread/fwrite were out and I decided on
fgetc/fputc. Is my code up to standards? And also can someone tell me what
the first int parameter of fputc is and does? My references that I look at
do not say. But I think I used it right. I guessed a 'container' for a char.

Bill
Jun 27 '08 #1
30 1365

"Bill Cunningham" <no****@nspam.c omwrote in message
news:V1aMj.3202 $Ho5.2125@trndd c01...
I began to think about some excercises I could with files after reading
turtorials today on arithmetic operators and confusing myself and decided
to do this.
Take the mv command from linux that moves and renames files read it as
binary and write it as text. After some compiler qipes it compiled and I
believe it did want I wanted it to.

#include <stdio.h>

int main(void) {
FILE *ifp, *ofp;
int a;
ifp=fopen("mv", "rb");
ofp=fopen("m"," wt");
a=fgetc(ifp);
if (a==EOF) {
fclose(ifp);
}
fputc(a,ofp);
if (a==EOF) {
fclose(ofp);
}
}

Because I didn't know how long the file would be I couldn't say exactly
how many bytes I should read so fread/fwrite were out and I decided on
fgetc/fputc. Is my code up to standards?
Not quite.

Try putting in a comment describing what it should do.

Try testing it to see that it does so!

--
Bart
Jun 27 '08 #2

"Bartc" <bc@freeuk.comw rote in message
news:1e******** ********@text.n ews.virginmedia .com...
Not quite.

Try putting in a comment describing what it should do.

Try testing it to see that it does so!
Well as far as testing it an EBCDIC file was written with characters so
it seems to work. But when I changed the ofp pointer and fopen's mode to wb
I got the same thing. So now I am doubting that I am getting what I want
though it seemed work.

Bill
Jun 27 '08 #3
"Bill Cunningham" <no****@nspam.c omwrites:
"Bartc" <bc@freeuk.comw rote in message
news:1e******** ********@text.n ews.virginmedia .com...
>Not quite.

Try putting in a comment describing what it should do.

Try testing it to see that it does so!
Well as far as testing it an EBCDIC file was written with characters so
it seems to work. But when I changed the ofp pointer and fopen's mode to wb
I got the same thing. So now I am doubting that I am getting what I want
though it seemed work.

Bill
You are trolling aren't you?
Jun 27 '08 #4

"Richard" <de***@gmail.co mwrote in message
news:ft******** **@registered.m otzarella.org.. .
You are trolling aren't you?
Where the hell did that come from? I am doubting that my code is doing
what I wanted and I would like to ask for serious feedback.

Bill
Jun 27 '08 #5
"Bill Cunningham" <no****@nspam.c omwrites:
"Richard" <de***@gmail.co mwrote in message
news:ft******** **@registered.m otzarella.org.. .
>You are trolling aren't you?

Where the hell did that come from? I am doubting that my code is doing
what I wanted and I would like to ask for serious feedback.

Bill
Here's some : step through it with a debugger. That will be specific to
your platform properly. Even a casual look at your code should tell you
it doesn't do what you want. Stepping through with a debugger will prove
invaluable since you clearly are a beginner in all aspects of
programming. Rather than take you through all the issues with your code,
try to figure it out yourself first. Go line by line and ask yourself
what it is doing and, as importantly, why.
Jun 27 '08 #6
On Sat, 12 Apr 2008 21:43:17 GMT, "Bill Cunningham" <no****@nspam.c om>
wrote:
I began to think about some excercises I could with files after reading
turtorials today on arithmetic operators and confusing myself and decided to
do this.
Take the mv command from linux that moves and renames files read it as
binary and write it as text. After some compiler qipes it compiled and I
believe it did want I wanted it to.

#include <stdio.h>

int main(void) {
FILE *ifp, *ofp;
int a;
ifp=fopen("mv", "rb");
ofp=fopen("m"," wt");
a=fgetc(ifp);
How do you ever get back to read another character.
if (a==EOF) {
fclose(ifp);
If you would learn to indent your code, it might make it much easier
for you to see where you are going wrong.
}
fputc(a,ofp);
if (a==EOF) {
fclose(ofp);
}
}

Because I didn't know how long the file would be I couldn't say exactly
how many bytes I should read so fread/fwrite were out and I decided on
Your comment makes no sense. Both fread and fwrite have methods for
specifying how many bytes to read/write and for informing the caller
how many bytes were actually read/written. You don't have to use them
but to say you can't is a limitation on you and not the functions.
>fgetc/fputc. Is my code up to standards? And also can someone tell me what
the first int parameter of fputc is and does? My references that I look at
do not say. But I think I used it right. I guessed a 'container' for a char.
You need a better reference. Find one that describes the purpose of
each parameter of all the standard functions. You can even find free
copies of the draft standard (n1124 and n1256) on the web which will
do this.
Remove del for email
Jun 27 '08 #7
On Sat, 12 Apr 2008 22:23:03 GMT, "Bill Cunningham" <no****@nspam.c om>
wrote:
>
"Bartc" <bc@freeuk.comw rote in message
news:1e******* *********@text. news.virginmedi a.com...
>Not quite.

Try putting in a comment describing what it should do.

Try testing it to see that it does so!
Well as far as testing it an EBCDIC file was written with characters so
it seems to work. But when I changed the ofp pointer and fopen's mode to wb
I got the same thing. So now I am doubting that I am getting what I want
though it seemed work.
Only for some strange definition of work. Your function doesn't
contain any form of looping. It executes fputc and fgetc each exactly
once. How can your function read or write more than one character?
Remove del for email
Jun 27 '08 #8
Only for some strange definition of work. Your function doesn't
contain any form of looping. It executes fputc and fgetc each exactly
once. How can your function read or write more than one character?
I'm not exactly sure how to use fgetc and fputc. This is the first time
I've put them into code so I'm a little confused on where in the loops to
put them. I've never really used debuggers though I have gdb. I don't think
it takes more than a keaner eye than mine to see the problems though.

Bill
Jun 27 '08 #9

"Barry Schwarz" <sc******@dqel. comwrote in message
news:j3******** *************** *********@4ax.c om...
> Because I didn't know how long the file would be I couldn't say
exactly
how many bytes I should read so fread/fwrite were out and I decided on

Your comment makes no sense. Both fread and fwrite have methods for
specifying how many bytes to read/write and for informing the caller
how many bytes were actually read/written. You don't have to use them
but to say you can't is a limitation on you and not the functions.
Exactly. Fread and fwrite require a buffer size and number of elements.
I just wanted to read the entire file without having to enter an exact size
so I don't think fwrite and fread would be the choice here.

Bill
Jun 27 '08 #10

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

Similar topics

0
1567
by: Stephan Deibel | last post by:
Hi, O'Reilly Associates has agreed to print a second volume of Python Success Stories and I am looking for contributors of new stories. This booklet will showcase Python in the context of a variety of successful software projects, explaining why Python was a good choice. It is used by O'Reilly as a freebie to market its own books, and it's a great way to get the word out about Python and your company or project.
0
1536
by: Stephan Deibel | last post by:
Hi, I just wanted to let y'all know that the Python Success Stories collection has nine new additions: http://www.pythonology.com/success These 28 stories include significant testimonials that can make it easier to sell technical decision-makers (i.e., your boss) on Python.
0
1325
by: Stephan Deibel | last post by:
Hi, O'Reilly Associates is going to be printing volume III of the Python Success Stories series in June and I'm looking for submissions of new stories. The stories have been quite valuable for people introducing Python to new users and companies. The deadline for me to receive stories for editing is May 1st and
1
2278
by: cmitchell | last post by:
Hi, I have daily backups set up for a database, however today i noticed in the Journal under task history i see under the success column that the status is expired. Normally the success column says successful or not successful. Any ideas? Cheryl
23
3032
by: | last post by:
hi i try to malloc 2G size mem . so i wirte code like that. it failt in freebsd 5.3 and win2k what's bug in my code ? how can i change it ? thank all :) benjiam
1
2276
by: audipen | last post by:
Hi, I trap the 'OnBuildProjConfigDone' and perform some custom enhancement to the assembly. I check the 'bool Success' parameter before I perform my step. I go ahead only if 'Success == true" My question is - Is there any way in which I can indicate success or failure of my post build step.. 'Success' is an in-parameter, so I cant set it to false. Also the return type of the handler is void.
0
1151
by: spam.noam | last post by:
Hello, What is the convention for writing C functions which don't return a value, but can fail? If I understand correctly, 1. PyArg_ParseTuple returns 0 on failure and 1 on success. 2. PySet_Add returns -1 on failure and 0 on success. Am I correct? What should I do with new C functions that I write?
1
2589
by: yuchang | last post by:
Hi, Using the FormView control is very efficient. But I want to do some action,like showing a success message or redirect to another page, after inserting, updating and deleting. How do I get these message?
45
2230
by: Nicholas M. Makin | last post by:
Well I have gone and done it. I started a fight with C/C++ programmers over whether VB was a good language. They seem to think it is a toy. Now I read SOMEWHERE that VB was either the most successful language of one of the most successful languages ever. I can not however find a source to support such a statment. I know that VB has lower development costs than C/C++ due to its speed of development and its memory mannagement, but again I...
5
3492
by: divingIn | last post by:
Hi, I have a form that should popup mentioning Success so i am using alert() box but it shows a yellow exclamation(!) which i dont want. Is there any other more intuitive kind of success message box i can use? TIA
0
9683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10457
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10231
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10013
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7550
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2927
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.