Message-ID: <3AB6AA85.A20AF326@earthlink.net> From: Martin Ambuhl X-Mailer: Mozilla 4.76 [en] (Win95; U) X-Accept-Language: en,zh-CN,fr,de-CH,ru MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: ASCII codes References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 54 Date: Tue, 20 Mar 2001 00:52:38 GMT NNTP-Posting-Host: 63.210.220.151 X-Complaints-To: abuse AT earthlink DOT net X-Trace: newsread1.prod.itd.earthlink.net 985049558 63.210.220.151 (Mon, 19 Mar 2001 16:52:38 PST) NNTP-Posting-Date: Mon, 19 Mar 2001 16:52:38 PST Organization: EarthLink Inc. -- http://www.EarthLink.net To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com jaystewart1 wrote: > > Can you guys help me write a program that outputs two strings and their > length, then outputs the two strings in alphabetical order? Show us (better: show comp.lang.c or alt.comp.lang.learn.c-c++) your attempt and we will try to help fix your code. > > The array below represents the ASCII codes for a string. Can anyone help me > write a program that outputs the corresponding string? > > int x[] ={65,112,114,105,108,32,115,104,111,119, > 101,114,115,32,98,114,105,110,103,32,77,97, > 121,32,102,108,111,119,101,114,115,32,33,0}; #include #include int main(void) { int x[] = { 65, 112, 114, 105, 108, 32, 115, 104, 111, 119, 101, 114, 115, 32, 98, 114, 105, 110, 103, 32, 77, 97, 121, 32, 102, 108, 111, 119, 101, 114, 115, 32, 33, 0 }; char *y; size_t i; if (!(y = malloc(sizeof x / sizeof *x))) { printf("Damn!\n"); exit(EXIT_FAILURE); } for (i = 0; i < sizeof x / sizeof *x; i++) y[i] = x[i]; printf ("The 'correctness' of the following output depends\n" "on the implementation using ASCII, by no means\n" "guaranteed by the standard. Here we go:\n %s\n\n", y); printf ("Note that 'y' in the above statement could not be replaced by\n" "(char *)x because x[0] interpreted as chars is \\%03o \\%03o\n", (char)*(char *)&x, (char)(*(1 + (char *)&x))); free(y); return 0; } The 'correctness' of the following output depends on the implementation using ASCII, by no means guaranteed by the standard. Here we go: April showers bring May flowers ! Note that 'y' in the above statement could not be replaced by (char *)x because x[0] interpreted as chars is \101 \000