Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFCCCC
char *strcat_nc(char *s1, char *s2);

char *str1 = "str1";
char const *str2 = "str2";
char str3[] = "str3";
char const str4[] = "str4";

strcat_nc(str3, str2);	/* Compiler warns that str2 is const */
strcat_nc(str1, str3);  /* Oops, attemptsAttempts to overwrite string literal! */
strcat_nc(str4, str3);  /* Compiler warns that str4 is const */

...

Code Block
bgColor#ccccff
char *strcat(char *s1, char const *s2); 

char *str1 = "str1";
char const *str2 = "str2";
char str3[] = "str3";
char const str4[] = "str4";

strcat(str3, str2);  
strcat(str3, str1);  

/* Args reversed to prevent overwriting string literal */ 
strcat(str3, str1);  
strcat(str4, str3);  /* Compiler warns that str4 is const */

...