I have this little problem with GCC which I wonder if anyone can enlighten me on. The little program below has been run on three different machines all with the same result. The program compiles OK under GCC but fails with a segmentation error. Under Borland 'C for DOS', it compiles and runs correctly.
Thanks in anticipation
David
/* Program to increment the chars in a string and print to screen. Works OK with Borland 'C for DOS' but fails with GCC 3.3 (segmentation error) -why???? */ #include <stdio.h>
void code(char *);
main()
{ code("This is a test string");
putchar('\n');
return 0;
}/* (*strptr)++ gets then increments the CHARACTER, while *strptr++ gets the CHARACTER then increments the POINTER */
void code (char * strptr)
{ while( *strptr)
{ (*strptr)++ ; //This line fails in GCC
//(*strptr) = (*strptr) + 1 ;// so does this
printf("%c", *strptr++);
}
}
-- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
