I'd like to store a string of characters into a character array. This string is intended to be a file format identifier, and would eventually be written to a file. The catch is that in compliance with the file format's specification, this string should not be null-terminated. Here's three different ways I've tried doing it:
What do you guys do when you need to assign a character string that is not null-terminated?Code:char format_id[4] = 'RIFF'; /* not sure if it's legal. I get a "multi-character character constant" warning * and unintended results */ char format_id[4] = {'R', 'I', 'F', 'F'}; /* this works but is awkward to type and harder to read */ char format_id[4] = "RIFF"; /* works with no compiler complaints, but aren't I assigning a null-terminated string * to an array of a smaller size? It's easy, but feels dirty. Is this bad form? */



LinkBack URL
About LinkBacks



