- Mar 12, 2001
- 968
- 0
- 0
I have been working with cc on a UNIX system. And this simple program comiles and runs fine:
------------------------------------------START-----------------------------------
#include <stdio.h>
char * strset(char * original, char letter);
main() {
char * word = "Rob";
char letter = 'x';
printf("%s\n", strset(word, letter));
}
char * strset(char * string, char letter) {
char * original = string;
while (*string)
*string++ = letter;
return(original);
}
------------------------------------END-------------------------------------
The problem is when I move this same program over to a Linux machine and use gcc it compiles fine but when I try to execute it, it Segmentation faults.
I've narrowed the problem down to this line:
*string++ = letter;
gcc will not let me increment a pointer. Does anyone know a way to do this?
------------------------------------------START-----------------------------------
#include <stdio.h>
char * strset(char * original, char letter);
main() {
char * word = "Rob";
char letter = 'x';
printf("%s\n", strset(word, letter));
}
char * strset(char * string, char letter) {
char * original = string;
while (*string)
*string++ = letter;
return(original);
}
------------------------------------END-------------------------------------
The problem is when I move this same program over to a Linux machine and use gcc it compiles fine but when I try to execute it, it Segmentation faults.
I've narrowed the problem down to this line:
*string++ = letter;
gcc will not let me increment a pointer. Does anyone know a way to do this?