[Courses] [C] Lesson12: Exercise answers
Eugene Teo
eugene.teo at eugeneteo.net
Thu Nov 21 12:21:44 EST 2002
More comments inline:
> stringpointer = stringlook(string);
> if (stringpointer == NULL) {
> printf("Did not find any non-whitespace characters.\n");
> } else {
> printf("Pointer reads: %c\n", *stringpointer);
> }
Personal preference. I find it more elegant to do:
if( !(stringpointer = stringlook(string)))
printf("lala");
else
printf("lalala");
> This sort of bug is very common. If you've ever seen "Segmentation
> Fault" on unix or "General Protection Fault" on windows, it's probably
> because something dereferenced an invalid pointer.
I have not seen GPF for a long time. Whoops, I forgot I haven't use
Windows for a long time :)
> > char *stringlook(char *string) {
> > unsigned short i;
> >
> > for(i=0; *(string+i) != '\0'; i++) {
> > if( *(string+i) != ' ') return (string+i);
> > }
> >
> > return 1;
>
> I would do:
> return NULL;
> here instead.
And include stdlib.h
> > }
>
> --
> laurel at sdf.lonestar.org
> http://dreadnought.gorgorg.org
> _______________________________________________
> Courses mailing list
> Courses at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/courses
--
eMail: eugeneteo at eugeneteo.net, eugeneteo at null.cc.uic.edu
gpg pub_key: http://null.cc.uic.edu/~eugeneteo/eugeneteo.asc
main(i){putchar(182623909>>(i-1)*5&31|!!(i<7)<<6)&&main(++i);}
More information about the Courses
mailing list