TIP: Click on subject to list as thread! ANSI
echo: locsysop
to: Bob Lawrence
from: Paul Edwards
date: 1994-05-28 09:43:34
subject: C

BL>   I've got 3:711/934.12 and I want to read the 711. How do I do it?

 BL>   In Pascal I'd use COPY("3:711/934.12",3,3); but how do you pick a
 BL> string out of a string in C?

Assuming you can guarantee that the substr is valid, ie at position 3 there
are 3 characters, then I would suggest:

char small[10];
char big[30];

strcpy(big, "3:711/934.12");
memcpy(small, big + 2, 3);  /* copy from position 2 for a length of 3 */
small[3] = '\0';            /* nul-terminate the C string */

Remember that C uses 0-based counting, and that for a string to be a string
it needs a NUL terminator.  memcpy() doesn't automatically put in a NUL
terminator.  If you would like to write a 2-line function that does the
copy AND puts in the terminating NUL, then feel free, it shouldn't take you
more than half an hour, and you can use it for the rest of your life.  BTW,
I think I told you to use gets() for that other problem.  fgets() is
probably more appropriate.

 BL>   I should explain that I haven't used Pascal for five years, and it
 BL> took me two minutes to find the right command. I've been arsing around
 BL> with C all day! And no closer than when I started.

You only have to learn it once.  Your C program will then work on MVS and
OS/2. Can you say the same about Pascal?  BFN.

Paul

--- GoldED/2 2.42.G1114
* Origin: This one HAS to be original XYPVH (3:711/934.9)

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.