Article View: comp.sys.lang.c++
Article #6Re: Question for C Programmers...
From: Karsten Roemke Zi.209 PIB
Date: Wed, 11 Sep 1996 00:00
Date: Wed, 11 Sep 1996 00:00
45 lines
2546 bytes
2546 bytes
bastards (bastards@ntic.qc.ca) wrote:
: 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);
: But, unfortunatly the "CHAR" function dosn't exist... :( so what should
: I do?
Maybe not the best solution, but one which works:
#include <stdio.h> /* input output*/
#include <stdlib.h> /* malloc (and more) */
#include <string.h> /* strlen (and more)*/
main()
{
char *test;
int i;
test = (char *) malloc(strlen("test")+2); /* +2 for the \0 and the
extra character you want to use */
sprintf(test, "%s%c\0","test",10);
for(i=0;i<strlen(test)+1;i++)
{
printf("%c %d\n",test[i],test[i]));
}
}
output:
t 116
e 101
s 115
t 116
10
0
10 written as character is linefeed.
Maybe you should read a book about C.
(kernighan and ritchie is nice)
-----------------------------
Karsten Roemke
email : roemke@space9.physik.uni-bonn.de
phone : 0228 212395
-----------------------------------------------
Technical Details
Message-ID:
<5161k7$khm@news.rhrz.uni-bonn.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: 10edc6,882dc48c93e679cf X-Google-Attributes: gid10edc6,public X-Google-Thread: 167642,882dc48c93e679cf X-Google-Attributes: gid167642,public X-Google-Thread: 10c73c,882dc48c93e679cf X-Google-Attributes: gid10c73c,public X-Google-Thread: 108b44,882dc48c93e679cf X-Google-Attributes: gid108b44,public X-Google-Thread: 10b7bb,882dc48c93e679cf X-Google-Attributes: gid10b7bb,public X-Google-Thread: 10caf2,882dc48c93e679cf X-Google-Attributes: gid10caf2,public X-Google-Thread: fffda,882dc48c93e679cf X-Google-Attributes: gidfffda,public From: roemke@PROBLEM_WITH_INEWS_DOMAIN_FILE (Karsten Roemke Zi.209 PIB) Subject: Re: Question for C Programmers... Date: 1996/09/11 Message-ID: <5161k7$khm@news.rhrz.uni-bonn.de> X-Deja-AN: 179901800 references: <01bb9f5e$eb2c1ea0$5caceccd@bastards.ntic.qc.ca> followup-to: comp.sys.lang.c++,ctdl.lang.c++,de.comp.lang.c++,fj.lang.c++,hepnet.lang.c++,ibm.ibmpc.c++,sb.lang.c++ organization: RHRZ - University of Bonn (Germany) newsgroups: comp.sys.lang.c++,ctdl.lang.c++,de.comp.lang.c++,fj.lang.c++,hepnet.lang.c++,ibm.ibmpc.c++,sb.lang.c++