Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | "Bill Cunningham" <nospam@nspam.invalid> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: code |
| Date | 2012-09-03 06:56 -0400 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <k222db$8n4$1@speranza.aioe.org> (permalink) |
| References | <k215tf$b93$1@speranza.aioe.org> <lnd323wuh2.fsf@nuthaus.mib.org> |
Keith Thompson wrote:
> "Bill Cunningham" <nospam@nspam.invalid> writes:
> [...]
>> The idea is to take a binary and convert it to text and
>> print it in hex. I never get out of the do-while loop. Like a hex
>> dump does but a hex dump doesn't convert a binary into text.
>
> A hex dump *does* convert a binary into text. What did you think a
> hex dump does?
>
> [...]
>
>> #include <stdio.h>
>> #include <stdlib.h>
>>
>> int main(void)
>> {
>> int buf[8200];
>> unsigned buf2[8200];
>> FILE *fp, *fp2;
>> if ((fp = fopen("6", "rb")) == NULL) {
>> perror("fopen 1");
>> exit(1);
>> }
>
> Your indentation is messed up. I suspect that you're indenting with
> a mix of spaces and tabs, and the tabs are getting lost somewhere
> between your news client and mine. Figure out how to indent with
> spaces only, at least for code you post. (Filtering through the Unix
> "expand" command is one way to do this.)
>
> [...]
>
>> do {
>> *buf = fscanf(fp, "%i", buf);
>> fprintf(fp2, "%i %x", *buf, *buf2);
>> }
>> while (*buf != EOF);
>
> For a do-while loop, it's clearer to put the while on the same line as
> the "}"; otherwise it looks very much like a while loop.
>
> [...]
>
> There are numerous other problems with your code.
>
> As you should realize by now, just getting a C program to compile
> doesn't imply that it's going to work. There are other languages
> where code that just compiles is more likely (though by no means
> certain) to work correctly. (Python springs to mind.) Of course
> you've been offered this advice before.
My indentation seems to always mess up when writing to a newsreader.
When I write code I do use a tab. For about every line then run it through
indent. The result looks perfect. Then I run it through unix2dos to
straighten out the lines and post from OE using my XP. Somewhere in there
the indentation messes up. I was leary about using fscanf and fprintf anyway
here. The thought was the conversion ability to turn binary to text.
B
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
code "Bill Cunningham" <nospam@nspam.invalid> - 2012-09-02 22:50 -0400
Re: code "Bill Cunningham" <nospam@nspam.invalid> - 2012-09-02 22:53 -0400
Re: code Barry Schwarz <schwarzb@dqel.com> - 2012-09-02 21:21 -0700
Re: code Keith Thompson <kst-u@mib.org> - 2012-09-02 22:23 -0700
Re: code "Bill Cunningham" <nospam@nspam.invalid> - 2012-09-03 06:56 -0400
Re: code Angel <angel+news@spamcop.net> - 2012-09-03 07:47 +0000
Re: code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-03 11:51 +0100
Re: code "Bill Cunningham" <nospam@nspam.invalid> - 2012-09-03 09:02 -0400
Re: code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-03 15:02 +0100
Re: code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-03 17:20 +0100
Re: code "Bill Cunningham" <nospam@nspam.invalid> - 2012-09-03 14:33 -0400
Re: code "Bill Cunningham" <nospam@nspam.invalid> - 2012-09-03 14:48 -0400
Re: code Keith Thompson <kst-u@mib.org> - 2012-09-03 13:11 -0700
Re: code "Bill Cunningham" <nospam@nspam.invalid> - 2012-09-03 17:41 -0400
Re: code Keith Thompson <kst-u@mib.org> - 2012-09-03 14:53 -0700
Re: code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-03 23:10 +0100
Re: code "osmium" <r124c4u102@comcast.net> - 2012-09-03 16:56 -0500
Re: code Keith Thompson <kst-u@mib.org> - 2012-09-03 18:27 -0700
Re: code "Bill Cunningham" <nospam@nspam.invalid> - 2012-09-03 17:50 -0400
Re: code "Bill Cunningham" <nospam@nspam.invalid> - 2012-09-03 17:54 -0400
Re: code Barry Schwarz <schwarzb@dqel.com> - 2012-09-03 15:12 -0700
Re: code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-03 23:23 +0100
Re: code "Bill Cunningham" <nospam@nspam.invalid> - 2012-09-03 18:42 -0400
Re: code "Bill Cunningham" <nospam@nspam.invalid> - 2012-09-03 19:11 -0400
Re: code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-04 00:16 +0100
Re: code "Bill Cunningham" <nospam@nspam.invalid> - 2012-09-03 20:01 -0400
Re: code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-04 02:07 +0100
Re: code "Bill Cunningham" <nospam@nspam.invalid> - 2012-09-03 21:17 -0400
Re: code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-04 02:24 +0100
Re: code Barry Schwarz <schwarzb@dqel.com> - 2012-09-03 20:55 -0700
Re: code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-04 11:16 +0100
Re: code Kenneth Brody <kenbrody@spamcop.net> - 2012-09-04 14:09 -0400
Re: code Kenneth Brody <kenbrody@spamcop.net> - 2012-09-04 14:07 -0400
Re: code "Bill Cunningham" <nospam@nspam.invalid> - 2012-09-04 18:35 -0400
Re: code Les Cargill <lcargill99@comcast.com> - 2012-09-04 18:49 -0500
Re: code "Bill Cunningham" <nospam@nspam.invalid> - 2012-09-04 20:56 -0400
Re: code "Bill Cunningham" <nospam@nspam.invalid> - 2012-09-04 22:05 -0400
csiph-web