Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I am working on a orca/c project and need "Learn to Program in C by Mike Westerfield"

126 views
Skip to first unread message

James Hall

unread,
May 25, 2022, 1:40:40 PM5/25/22
to
I am having some trouble getting a little bit of text formatting to display correctly. I was hoping some-one might have a link to "Learn to Program in C by Mike Westerfield". I think i had downloaded and then printed it out along with the Orca/C manual from Byteworks Morgue site many moons ago. I have come across the pdf on scribd.com, I have not had a lot of luck with that site. Oh, and Mac.Gui has a nice picture of the cover page! Thanks for tormenting me Mac.Gui. lol.

And that printed version is 3500kms away as well as at the bottom of the pile of my ][gs tools, locked away in storage. Someday soon i will have it all back in it's rightful place on shelves where i can reach and read it again. In the mean time! Can anyone point me in the right direction?

Thanks for taking the time to read this.

apple ][ forever.

James
ve3myz

Craig Ruff

unread,
May 25, 2022, 7:52:19 PM5/25/22
to
In article <b34f59d2-8c40-4326...@googlegroups.com>,
James Hall <james.ha...@gmail.com> wrote:
>I am having some trouble getting a little bit of text formatting to
>display correctly. I was hoping some-one might have a link to "Learn to
>Program in C by Mike Westerfield".

Perahps you can describe what you are trying to do and what isn't
working and we can provide suggestions? I've been using C for 40 years,
and as long as it isn't something Apple IIgs specific I might be able
to help.

James Hall

unread,
May 25, 2022, 9:33:03 PM5/25/22
to
> Perahps you can describe what you are trying to do and what isn't
> working and we can provide suggestions? I've been using C for 40 years,
> and as long as it isn't something Apple IIgs specific I might be able
> to help.

Hi Craig, Thanks for the reply.

I am working on \t that i understand is TAB. I have been looking over the Orca/C code i have here and i do not see the \t being used.

This is one of the lines i am trying for format correctly in Orca/C. printf("0\t\t%.9f\t\t%.9f\n",output[0],zero);

The 9 point float is not aligning when i replace the \t\t with 8 spaces. I have also looked through my APW/C manuals and don't see \t defined there as well.

Thanks


James

tsma...@gmail.com

unread,
May 26, 2022, 12:20:01 PM5/26/22
to
> This is one of the lines i am trying for format correctly in Orca/C. printf("0\t\t%.9f\t\t%.9f\n",output[0],zero);

Number formatting in C (and its offspring) has a lot going on. One thing to note is that %.9f means to print 9 digits of precision (i.e. digits after the decimal place) - if you're trying to make things line up in a table, you probably want to indicate the field width, which you could do by just %9f (no period), and if you wanted to combine them: %9.2f for a field with two digits after the decimal, taking up (at least) 9 spaces.

Perhaps you're already familiar with all of that - if so, please forgive the review.


> The 9 point float is not aligning when i replace the \t\t with 8 spaces.

If you remove the tabs and it's still not working, my guess is that something else (probably the float layout) is the problem. Can you show us the expected output and the output you're getting?


> I have also looked through my APW/C manuals and don't see \t defined there as well.

That's curious - I would expect that \t would be implemented somehow in any C implementation, though possibly inconsistently.

Another thought I have is that maybe the console is ignoring the tab character, and using spaces is what you're expected to do. It's been a long time since I've done any IIgs programming.

-Dave LeCompte

Stephen Heumann

unread,
May 26, 2022, 6:57:03 PM5/26/22
to
On 2022-05-26 01:33:02 +0000, James Hall said:
>
> I am working on \t that i understand is TAB. I have been looking over
> the Orca/C code i have here and i do not see the \t being used.

ORCA/C does support the \t escape sequence, but the IIGS console
ignores tabs, which is why they don't appear to show up in the output.
For output to the console, you will need to just use spaces instead.
(The tabs will show up if you look at the output in something that
supports them, e.g. by redirecting output to a text file and then
opening that file in an editor.)

With regard to the Learn to Program in C book, the PDF of it is
available on Opus ][.

--
Stephen Heumann

Craig Ruff

unread,
May 26, 2022, 7:25:16 PM5/26/22
to
In article <48521c41-a6b6-4909...@googlegroups.com>,
tsma...@gmail.com <tsma...@gmail.com> wrote:
>That's curious - I would expect that \t would be implemented somehow in any C implementation, though possibly
>inconsistently.

Presumably it is implemented since it is defined by the C standard.
The "\t" escape places a 0x09 byte in the string at that point.

>Another thought I have is that maybe the console is ignoring the tab character, and using spaces is what you're
>expected to do. It's been a long time since I've done any IIgs programming.

This is almost certainly the case, or there is a mismatch in what the
programmer expects the tab stops (tab width) to be vs the software that
is rendering the tabs into spaces. This is why many programming
standards now specify indentation as a specific number of spaces and
that use of tab characters is prohibited. That way everyone sees the
same representation, which you may not see when using tab characters.

James Hall

unread,
May 27, 2022, 2:17:29 AM5/27/22
to
Thank you Stephen Heumann, That statement jogs a memory.

Here's the VanillaC source.

printf("\ntype 16 point input vector\n");
scanf("%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f",&data[0],&data[1],&data[2],&data[3],&data[4],&data[5],&data[6],&data[7],&data[8],&data[9],&data[10],&data[11],&data[12],&data[13],&data[14],&data[15]);

R16SRFFT(data,output);
printf("\nresult is:\n");
printf("k,\t\tReal Part\t\tImaginary Part\n");
printf("0\t\t%.9f\t\t%.9f\n",output[0],zero);
printf("1\t\t%.9f\t\t%.9f\n",output[1],output[9]);
printf("2\t\t%.9f\t\t%.9f\n",output[2],output[10]);
printf("3\t\t%.9f\t\t%.9f\n",output[3],output[11]);
printf("4\t\t%.9f\t\t%.9f\n",output[4],output[12]);
printf("5\t\t%.9f\t\t%.9f\n",output[5],output[13]);
printf("6\t\t%.9f\t\t%.9f\n",output[6],output[14]);
printf("7\t\t%.9f\t\t%.9f\n",output[7],output[15]);
printf("8\t\t%.9f\t\t%.9f\n",output[8],zero);
printf("9\t\t%.9f\t\t%.9f\n",output[7],-output[15]);
printf("10\t\t%.9f\t\t%.9f\n",output[6],-output[14]);
printf("11\t\t%.9f\t\t%.9f\n",output[5],-output[13]);
printf("12\t\t%.9f\t\t%.9f\n",output[4],-output[12]);
printf("13\t\t%.9f\t\t%.9f\n",output[3],-output[11]);
printf("14\t\t%.9f\t\t%.9f\n",output[2],-output[9]);
printf("15\t\t%.9f\t\t%.9f\n",output[1],-output[8]);
}

Here is what i am expecting for output.
result is:
k, Real Part Imaginary Part
0 -2.749192238 0.000000000
1 1.549032927 1.325549364
2 -0.874582291 1.874609947
3 4.200131416 1.325549364
4 1.000027657 0.000000000
5 4.200131416 -1.325549364
6 -0.874582291 -1.874609947
7 1.549032927 -1.325549364
8 -2.749192238 0.000000000
9 1.549032927 1.325549364
10 -0.874582291 1.874609947
11 4.200131416 1.325549364
12 1.000027657 -0.000000000
13 4.200131416 -1.325549364
14 -0.874582291 -1.325549364
15 1.549032927 2.749192238


Here is what Orca/C gives you.
result is:
k,Real PartImaginary Part
08.00000000000000000000.0000000000000000000
11.0000000000000000000-5.0273394584655761719
20.0000000000000000000-0.0000000000000000000
31.0000000000000000000-1.4966056346893310547
40.00000000000000000000.0000000000000000000
51.0000000000000000000-0.6681787967681884766
60.00000000000000000000.0000000000000000000
70.9999999403953552246-0.1989121437072753906
80.00000000000000000000.0000000000000000000
90.99999994039535522460.1989121437072753906
100.0000000000000000000-0.0000000000000000000
111.00000000000000000000.6681787967681884766
120.0000000000000000000-0.0000000000000000000
131.00000000000000000001.4966056346893310547
140.00000000000000000005.0273394584655761719
151.0000000000000000000-0.0000000000000000000

When you replace the \t with 4 spaces for each occurrence of TAB, the - symbol on negative numbers do not line up.
When you add extra space to line the values up, any change to the input values change the output values and again things do not line up again.

My change, is to the float output from 9 to 19 decimal places. You can see in the Orca/C output the Positive Value Whole Number is where the Negative Symbol shows up when Negative Numbers are the output result. Also you can see that the decimal points do not line up.

Question: How do i line up the positive and negative first digits as well as the decimal points.

thank you all for the input.

James

Craig Ruff

unread,
May 27, 2022, 8:19:13 AM5/27/22
to
The trick is probably to specify the field width to include the width of
the column you want your numbers to fit inside including the sign, the
largest integer part the decimal point and the maximum precision for the
fraction you need and to not use tabs at all.

t.c:
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv)
{
double a, b;

a = 123.456789;
b = -1.8435430;
printf("%15.6f %15.6f\n", a, b);
a = -0.6492856435;
b = 3452.3902587320;
printf("%15.6f %15.6f\n", a, b);
exit(0);
}

The output:
% ./t
123.456789 -1.843543
-0.649286 3452.390259

tsma...@gmail.com

unread,
May 27, 2022, 11:18:59 AM5/27/22
to
> Question: How do i line up the positive and negative first digits as well as the decimal points.

Do you want the decimal points lined up, the first digits lined up, or the negative signs (if any) lined up? With data of different magnitudes like 0.0, 10.0, 100.0, -1000.0, you won't be able to get all three.

For me, I'd try

printf("%d %10.2f %10.2f %10.2f\n", n, real[n], imag[n], qual[n]);

and then tweak from there.

James Hall

unread,
May 27, 2022, 3:53:33 PM5/27/22
to
Thank you again for the help! While i have not tried either of the last two solutions, yet. I promise i will try them both over the weekend. What keeps coming to mind is; to me it seems the alignment issue is being generated anytime there is a -Negative number! Is it possible to force orca/c to generate a +Positive sign in-front of all Positive Values. Would this resolve it ?

Thanks again for being there to suggest and bounce idea's off.

regards
James
ve3myz

Apple ][ forever.

Stephen Heumann

unread,
May 27, 2022, 10:54:36 PM5/27/22
to
On 2022-05-27 19:53:32 +0000, James Hall said:

> What keeps coming to mind is; to me it seems the alignment issue is
> being generated anytime there is a -Negative number! Is it possible to
> force orca/c to generate a +Positive sign in-front of all Positive
> Values. Would this resolve it ?

You can force it to generate a + sign for positive numbers by including
the "+" flag in the format specification, e.g. "%+.9f". That should
cause numbers with a magnitude less than 10 to line up when printed.

If you will be dealing with a wider range of magnitudes, you will need
to figure out what part(s) of the numbers you want lined up, since they
would have different numbers of digits before the decimal point. One
possibility is to specify that the numbers should be padded with zeros
up to a certain field width, which you can do by including the "0" flag
and an explicit field width in the format specification, e.g.
"%+015.9f". (Very large numbers still won't line up if they have too
many digits before the decimal point, so you will need to pick a field
width that accommodates numbers within the range you intend to use.)

--
Stephen Heumann

James Hall

unread,
May 28, 2022, 3:02:25 AM5/28/22
to
Thank Stephen, the + worked a charm. (:
And thank you again for the reminder of the orca console note. I recompiled using Prizm, that worked with the
\t. At this point, i am happy with the output, it is just to test my own mathlib against an original C program that needs 63 integers and 20 decimal points resolution.

Thank you as well to Craig, i have added the snippet to my source library and feel confident i will integrate it into some code.

Thank you tsma...@gmail.com, your snippet is what i was thinking would need to be done. Neat & Simple.

My change is "%+020.20f", with just a single extra space inserted for k, 1 ~ 9.

> You can force it to generate a + sign for positive numbers by including
> the "+" flag in the format specification, e.g. "%+.9f". That should
> cause numbers with a magnitude less than 10 to line up when printed.
> --
> Stephen Heumann


Apple ][ ForEver
James [ve3myz] 73
0 new messages