comma in string

D

D

How do you put a comma in a string that's passed
as a function argument. The compiler thinks it's the
end of that argument and I've tried the /, and "," but
they don't seem to work.
 
T

Tom St Denis

D said:
How do you put a comma in a string that's passed
as a function argument. The compiler thinks it's the
end of that argument and I've tried the /, and "," but
they don't seem to work.

Um, printf("hello,world\n");

Will compile and execute just fine.

Tom
 
D

D

umm, I then suspect this may be an OS problem and not a C problem.
I getting a problem with the Windows MessageBox function, the
compiler is balking with the comma inside of the message string.
 
J

Joona I Palaste

D said:
umm, I then suspect this may be an OS problem and not a C problem.
I getting a problem with the Windows MessageBox function, the
compiler is balking with the comma inside of the message string.

It's most certainly an OS problem. In C, the comma has no special
meaning inside string literals, a comma is a comma is a comma.
 
M

Martin Johansen

D said:
umm, I then suspect this may be an OS problem and not a C problem.
I getting a problem with the Windows MessageBox function, the
compiler is balking with the comma inside of the message string.


Check the preceding code, there may be an error there which leads to this.
 
N

nrk

Joona said:
It's most certainly an OS problem. In C, the comma has no special
meaning inside string literals, a comma is a comma is a comma.
It might also be a user problem. Perhaps OP hasn't escaped double quotes
inside the string or some such?

-nrk.
 
M

Martin Ambuhl

D said:
How do you put a comma in a string that's passed
as a function argument. The compiler thinks it's the
end of that argument and I've tried the /, and "," but
they don't seem to work.

You'll have to show some code, since the behaviour you report is bizarre.
See what happens with the following code:

#include <stdio.h>

void showargs(const char *s, const char *t, int n)
{
printf("This function displays two string arguments,\n"
"followed by an integer one.\n"
"first string: \"%s\"\n"
"second string: \"%s\"\n" "the integer: %d\n", s, t, n);
}


int main(void)
{
showargs("This string has a comma (,) in it.",
"For that matter, so does this one.", 42);
return 0;
}


This function displays two string arguments,
followed by an integer one.
first string: "This string has a comma (,) in it."
second string: "For that matter, so does this one."
the integer: 42
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,139
Messages
2,570,807
Members
47,356
Latest member
Tommyhotly

Latest Threads

Top