>>foo( "" );
>>It doesn't crash though. So at least that's good.
Lucky more like Modifying string literals is a no no.
@Stack Overflow: If all you're looking for is a quick way to terminate a string at the first occurence of a particular character (which is what the "strip newline" type functions you've created do), try this:
Code:
#include <stdio.h>
void foo(char *s, int c)
{
while (*s && *s != c)
{
s++;
}
*s = '\0';
}
int main(void)
{
char n[] = "blahh\n";
char m[] = "\n";
printf("n after >%s<\n", n);
foo(n, '\n');
printf("n after >%s<\n", n);
printf("m before >%s<\n", m);
foo(m, '\n');
printf("m after >%s<\n", m);
return(0);
}