S
Sheky
Could anybody please mention difference between character array and
string in C?
string in C?
There's not much difference. In C, a string is an array of charactersCould anybody please mention difference between character array and
string in C?
Could anybody please mention difference between character array and
string in C?
Could anybody please mention difference between character array and
string in C?
Could anybody please mention difference between character array and
string in C?
To my knowledge, C does not have strings.
It has syntactic support for strings, as string literals. It also hasTo my knowledge, C does not have strings.
Sheky said:Could anybody please mention difference between character array and
string in C?
For unicode support in C is documented in C99. In C89 the 8-bit ANSI char
string was assumed
and the termination of a string is a 0 stored [at] the [end] of a string.
In some encoding C-code compiled to deal with ANSI C string might fail.
This was what I tested long time ago.
In
--some--
programming languages length of a string might be stored explicitly in 2 to 4 bytes. Be careful of the length of two bytes stored that will cause trouble.
I think that the wchar that could support unicode can enhance the PC platform over the unix-lynux platform that might not support unicode in non-English users.
See 7.1.1p1, which I cited in my own response to Quentin.
C doesn't have a string type, but that's a very different question.
For unicode support in C is documented in C99. In C89 the 8-bit ANSI char
the character code you are trying to refer to is "ASCII" not "ANSI"
Sometimes it's harder than it looks.no. All conforming implementations must use zero to terminate a
string.
Badly written C programs might assume a particular character encoding.
But it isn't hard to write programs that are character encoding
neutral.
For instance IFF files have 4-letter ASCII tags which indicate what
sort of "chunk" you are reading. So the obvious thing to write is
fread(chunk, 1, 4, fp);
if(!strncmp(chunk, "DATA", 4))
/* we've got a data chunk */
That will break on a non-ascii system. The solution is to hardcode the
values. But then you can no longer read the word "DATA" and it becomes
a lot harder to see that the chunk identifier is correct.
James Kuyper wrote:
) On 11/09/2011 10:48 AM, Malcolm McLean wrote:
) ...
)> For instance IFF files have 4-letter ASCII tags which indicate what
)> sort of "chunk" you are reading. So the obvious thing to write is
)>
)> fread(chunk, 1, 4, fp);
)> if(!strncmp(chunk, "DATA", 4))
)> /* we've got a data chunk */
)>
)> That will break on a non-ascii system. The solution is to hardcode the
)> values. But then you can no longer read the word "DATA" and it becomes
)> a lot harder to see that the chunk identifier is correct.
)
) You can make it a macro, whose name is more informative than the
) hardcoded values. However, the better solution (though not always
) feasible) is to convert those files from ASCII to the native encoding on
) that platform,
They are not ASCII files. They are binary files with chunks that are
identified by a 4-byte header which has meaning when read as ASCII.
James Kuyper said:That makes it harder; the conversion utility would have to know about
the file format. It's still not impossible, but obviously far less
convenient.
It would be easy enough to write such a utility for IFF files, becauseThat makes it harder; the conversion utility would have to know about
the file format. It's still not impossible, but obviously far less
convenient.
It would be easy enough to write such a utility for IFF files, because
they have a structure whereby you have a "chunk" length, and
identifier telling you what sort of chunk it is. So you can just skip
through all the chunks, changing the identifier tags from ASCII to
EBCDIC.
But then you'd have two file formats, identical except for the tags,
and the potential for extra costs and incompatibilities would be
large. A bit like the decision to encode newline/carriage return as
just a newline. It saved a byte, but to this day text files won't
display properly on Windows as a result.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.