I'm porting a program that works with Ubuntu 8.04 (gcc version 4.2.4) to 10.04 (gcc version 4.4.3). I have the following code:
#include <stdio.h>
#include <string.h>
int main(void) {
char p[100] = "////abcd";
char *t;
/* Remove duplicate slashes, saving only one of them */
while (t = strstr(p, "//"))
strcpy(t, t + 1);
printf("%s\n", p);
return 0;
}
The result should be /abcd
, which it is with gcc 4.2.4. With 4.4.3, the output is /accd
.
Can you suggest me a code change that will give the correct output using both versions of gcc, and preferrably explain what is going on here.
Thanks in advance!