TIP: Click on subject to list as thread! ANSI
echo: locsysop
to: Bob Lawrence
from: Roy McNeill
date: 1995-04-23 21:29:18
subject: C

Hi Bob



 PE> I either use time(), a stopwatch, or a profiler. Check out

 PE> tprof.



 BL>   Ahh... so I'm wasting my fucking time(). How pathetic. If I want to

 BL> try various code for speed, I have to (1) run the code a thousand

 BL> times in a loop so I can use time() in seconds to get milliseconds, or

 BL> (2) exit the compiler, load the profiler (having learned WTF it is),

 BL> try the change, and then go back again. Great. This is how the

 BL> dinosaurs got theirs, Paul... lack of intelligence.



The profiler is quite a useful tool, I've found. You can measure

timings in all parts of your program a lot more easily than by

putting time() functions all over the place and adding multiple

loops (gotta be careful there, if the compiler is set to optimize

for speed, it may be able to spot a futile loop and omit it...).



One of the big strengths of the profiler is that it can point out

sluggish bits of code in places you never thought of looking.



The delay involved in switching between the IDE and the profiler

didn't really bother me. In each subdir, I had a file called C.BAT

which contained "bc hello.prj" or equivalent. If I was using the

profiler a lot there would also be TP.BAT, "tf386 hello.exe". (I

was using BC3v0, some of the prognames may be a bit different in 3v1.)



 BL>   The more I use C, the more I see the emperor's new clothes. I spent

 BL> most of yesterday afternoon discovering that C has no instr() function

 BL> for strings.



What's instr()?



 BL> VB has just the two basic functions for strings mid() and

 BL> instr(), and useless bloody C has neither. I've had to write my own!

 BL> C has 20 different strxxx() functions, and none of then is worth a

 BL> shit. Incredible.



One of the good things about C is its wealth of functions. Take a

closer look at the strxxx() collection, you'll find a few that

you'll use a lot (eg strcat, strcpy, strncpy, strcmp, strlen), and

the rest just stay in the back of the mind. Don't try to memorize

them all (I never have), just remember that "something like that

exists, I'll go look it up". In the IDE that's just an F1 key away.



 BL> In fact, I've given up thinking about strings in C.

 BL> It's an array, so I just treat it that way, write my two basic loops,

 BL> and go from there.



Good idea. Thinking of a string as an array of chars will keep you

aware that it has a certain size, unlike the free-form strings in

Basic.



 BL> ... [STOP PRESS!]



 BL>   I've just discovered that it hasn't got a mid() function either! I

 BL> don't believe it!



Huh? To copy out K characters starting at character M (M=0 for 1st

char) from string Instr to string Outstr, try



J = strlen(Instr);

if( (M < J) && ((M+K) <= J))

  {

   strncpy( Outstr, Instr+M, K);  /* direct equivalent of mid() */

   Outstr[J] = '\0';   /* see strncpy() docs for why */

  }

else

  printf("K and/or M too big...\n");



Does the same thing, but has full control if things go wrong. How

does mid() react if the input string is too short?



 BL> .... You only need two functions to manipulate strings,

 BL> and C hasn't got either of them! ROFL! Bloody hell.



Huh? again... Can Basic do a case insensitive string comparison?

(see stricmp())



Cheers



ps take heart - when this is over you'll be able to write a book

entitled "Learning C On A Mental Budget"



--- PPoint 1.88


* Origin: Silicon Heaven (3:711/934.16)
SEEN-BY: 711/934
@PATH: 711/934

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™.