Re: A89: Re: Strings in C


[Prev][Next][Index][Thread]

Re: A89: Re: Strings in C




The first question is somewhat easy (and it is the same in UNIX C),
check out strcat(...)

For example:
   char string1[9] = "blah";
   char string2[5] = "blah";

   strcat(string1,string2);
// Now string1 = "blahblah"
// Be careful to allocate enough memory for the string because the
string is attached regardless

If you don't want to overwrite string1 you could obviously allocate
another string for it:
   char string1[5] = "blah";
   char string2[5] = "blah";
   char string3[9] = {};

   strcpy(string3,string1);   
   strcat(string3,string2);

And so on... As for the second question, the method in which the ascii
value is stored it important. If it is already stored as a numeric data
type, you can simply cast:

   int ascii = 64;
   char chr  = (char) ascii;

But if it is stored as a string then you must use atoi(...) to turn the
string to a numeric first:

   char ascii[] = "64";
   char chr = (char) atoi(ascii);

Hope that helps...

Josh 'Gage' wrote:
> 
> i can answer the first question in standard UNIX C, but i doubt the stdio
> cmds match
> ----- Original Message -----
> From: "Peter David" <lilpjd@yahoo.com>
> To: <assembly-89@lists.ticalc.org>
> Sent: Thursday, September 21, 2000 7:56 AM
> Subject: A89: Strings in C
> 
> >
> > 2 Questions.
> > 1. How do you append a string in C
> >      TI-BASIC is "string1"&"string2"
> > 2. How do you convert a ascii value to a string
> > character.
> >
> >
> > =====
> > Equality cannot be reached until everyone accepts each other as different,
> which is what truly makes us equal.
> >     -Peter
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Send instant messages & get email alerts with Yahoo! Messenger.
> > http://im.yahoo.com/
> >

-- 
Scott "Wrath" Dial
wrath@calc.org
ICQ#3608935
Member of TCPA - tcpa.calc.org
PGP key available
_______________________________________________
Why pay for something you could get for free?
NetZero provides FREE Internet Access and Email
http://www.netzero.net/download/index.html



References: