fork download
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. int main()
  5. {
  6.  
  7. char FileName[7]; // space for 6 characters + 1 for the nul terminator
  8. FileName[0] = '0';
  9. FileName[1] = '1';
  10. FileName[2] = '2';
  11. FileName[3] = '3';
  12. FileName[4] = '4';
  13. FileName[5] = '5';
  14. FileName[6] = '\0'; // Very important to add a 0 at the end of the char array, to make a valid C-string
  15. printf( "FileName = %s\n", FileName );
  16.  
  17. char FileNameWithSlash1[8] = "/"; // space for `/` + file name
  18. strcat( FileNameWithSlash1, FileName );
  19. printf( "FileNameWithSlash1 = %s\n", FileNameWithSlash1 );
  20.  
  21. char FileNameWithSlash2[8]; // space for `/` + file name
  22. sprintf( FileNameWithSlash2, "/%s", FileName );
  23. printf( "FileNameWithSlash2 = %s\n", FileNameWithSlash2 );
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 5296KB
stdin
Standard input is empty
stdout
FileName = 012345
FileNameWithSlash1 = /012345
FileNameWithSlash2 = /012345