Article View: comp.sys.lang.c++
Article #7Re: Question for C Programmers...
From: Kurt Watzka
Date: Wed, 11 Sep 1996 00:00
Date: Wed, 11 Sep 1996 00:00
44 lines
2449 bytes
2449 bytes
"bastards" <bastards@ntic.qc.ca> writes: >Hi! First : I'm new to C language. :) >Second: I would like to know if somebody could tell me how I could add a >Caractere "0" after a string... something like: >My_String = "A_TEST" + CHR(10); The problem is not how to get a character from the numeric value 10. '\xA' is an integer constant that is what you are looking for. When adding a '0' after a string, the problem is not how to represent the character '0'. Your _real_ problem is that char * My_string = "This is a string" + '\xA'; is a strange way to get a pointer to the string "string" in C. Adding something to a string literal does not do what you expect it to do. If the buffer that holds the string is big enough, the following piece of code should do what you want: char My_string[BIG_ENOUGH] = "This is a string"; char *p = strchr(My_string, 0); *p++ = 10; *p = 0; >But, unfortunatly the "CHAR" function dosn't exist... :( so what should >I do? Regarding the conversion of integers to characters, the conversion is done automatically, and the "only" caveat is that the integer value must not exceed the domain (range of representable values) of char. Kurt -- | Kurt Watzka Phone : +49-89-2180-6254 | watzka@stat.uni-muenchen.de
Technical Details
Message-ID:
<5165bd$ams@sparcserver.lrz-muenchen.de>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<01bb9f5e$eb2c1ea0$5caceccd@bastards.ntic.qc.ca>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 167642,882dc48c93e679cf X-Google-Attributes: gid167642,public X-Google-Thread: 108b44,882dc48c93e679cf X-Google-Attributes: gid108b44,public X-Google-Thread: 10caf2,882dc48c93e679cf X-Google-Attributes: gid10caf2,public X-Google-Thread: 10c73c,882dc48c93e679cf X-Google-Attributes: gid10c73c,public X-Google-Thread: 10edc6,882dc48c93e679cf X-Google-Attributes: gid10edc6,public X-Google-Thread: 10b7bb,882dc48c93e679cf X-Google-Attributes: gid10b7bb,public X-Google-Thread: fffda,882dc48c93e679cf X-Google-Attributes: gidfffda,public From: watzka@stat.uni-muenchen.de (Kurt Watzka) Subject: Re: Question for C Programmers... Date: 1996/09/11 Message-ID: <5165bd$ams@sparcserver.lrz-muenchen.de> X-Deja-AN: 179908220 distribution: world references: <01bb9f5e$eb2c1ea0$5caceccd@bastards.ntic.qc.ca> organization: Institut fuer Statistik der LMU Muenchen (Germany) reply-to: watzka@stat.uni-muenchen.de newsgroups: comp.sys.lang.c++,ctdl.lang.c++,de.comp.lang.c++,fj.lang.c++,hepnet.lang.c++,ibm.ibmpc.c++,sb.lang.c++