Portability help
Dave Kraft
davek at lakesys.UUCP
Mon Feb 13 07:48:16 AEST 1989
Hi,
I am taking a C class in school this semester, and the instructor gave us the
following example:
#include <stdio.h> /* Please note: I used <dos/stdio.h> in the unix
environment */
main()
{
char a, b, c, d, e;
char whats_left[20];
int x;
printf("\nKey in a bunch of characters like 1234...9cr: ");
scanf("%c%c%c", &a, &b, &c);
printf("\nYou typed in >>%c%c%c<<", a, b, c);
scanf("%c%c", &d, &e);
printf("\nYou had these left over >>%c%c<<", d, e);
putc('\n', stdout);
scanf("%s", whats_left);
printf("\n>>%s<<", whats_left);
printf("\n>>%s<<", &a);
x = getchar();
if(x == EOF)
printf("\nInput stream empty.");
else;
printf("\nGot back >>%d%x<<", x, x);
}
I have entered and compiled this on Turbo C 1.5, and it runs like it should.
I enter: 123456789
and the first thing it prints is the >>123<<, then >>45<<, then >>6789<<,
then >>123456789<<, and I get 'Got back >>10a<<'
On the Unix system I enter the same numbers, and I get >>123<< >>45<< >>6789<<
and here's one of the kludges: >>126789<<, and for 'Got back', it shows
>>00<<.. Why?
Also, when I try to re-direct as follows:
1) example > output
123456789 (<-- what I type in after (1))
then I get a core dump, and a message (do not remember exactly,
will redo and post)
2) example < numlist > output (numlist contains 123456789)
I get the same core dump as in (1). Why??
Any help would be appriciated.
Dave
);
--
davek at lakesys.lakesys.com
uunet!marque!lakesys!davek
More information about the Comp.lang.c
mailing list