delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/23/18:45:29

From: myknees AT aol DOT com (Myknees)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Some easy questions (for you!)
Date: 23 Feb 1998 23:34:31 GMT
Lines: 69
Message-ID: <19980223233401.SAA26349@ladder02.news.aol.com>
NNTP-Posting-Host: ladder02.news.aol.com
References: <3 DOT 0 DOT 5 DOT 32 DOT 19980223220018 DOT 0079b850 AT vip DOT cybercity DOT dk>
Organization: AOL http://www.aol.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

"Nils Emil P. Larsen" <Peter_Larsen AT vip DOT cybercity DOT dk> writes:
> Thank you for DJGPP!
> 
> I need some help for working with strings:

A good book for learning C would be best.

> - How do I add a string to the end of another:
>   e.g. Str1 = "Thank "; Str2 = " you!";
>        Str3 = ???(Str1, Str2) /* Str3 must be: "Thank you
>        you!". What is ??? */

These questions are not really on topic for this newsgroup, since they have
more to do with C than djgpp per se, but heck---try this:

#include	<stdio.h>
#include	<string.h>

int main(void)
{
    /* Str3 must have enough room for the letters plus a null char. */
    char Str1[] = "Thank ";
    char Str2[] = "you!";
    char Str3[11];

    /* Str3 contains garbage, so make it a null string first. */
    Str3[0] = '\0';
    /* string concatenate(onto this, this) */
    strcat(Str3, Str1);
    strcat(Str3, Str2);

    printf("Survey says...\n");
    printf("%s\n", Str3);    

    /* there are other ways to do it, of course */
    return 0;
}

Get in the habit of using the documentation.  For example, invoke info.exe like
this:
info libc func string

> - How do I convert between strings and numbers? I want
> to use it like that:
>   Str1 = "Birthday: " + Int1 /* Str1 must be "Birthday: (
>   (value of int1)" */
>   OR
>   Int1 = Str1 /* Int1 must contain the number in Str1 */

You lost me there.  I think you really would do well to read an intro-to-C
book.  Once you know what strings are (arrays of characters with the null
character at the end) and what numbers are (something completely different from
strings), you'll know what you're trying to do.

Once you know what you're going for, take a look at that documentation again. 
e.g. Check out the function atoi().
 
> - Where can I get help for beginners in DJGPP? I don't
> think any of my
> DJGPP-FAQ's contain info for people who don't know C.
> Especially are I
> searching for help on the keywords (for, do...while,
> if...then...else ....).

Help with C basics is not specific to djgpp.  You can find it in lots of
places.  DJGPP is great for learning C, but you need to find ways to educate
yourself.

--Ed (Myknees)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019