I am saving the output of my program in .csv file.
I need to save a variable's value in one column, but the value may contain comma.
When the program encounters a comma it places half of the variable's value in
the next column.

Is there any way through which I can avoid the placement of value in the next column..

Put the thing in quotes
1,"hello, world",2
would be 3 columns.

Use excel to save a simple csv format file with a field containing a comma.

If double quotes are used it prints the variable name instead of value...

Or you could just post some actual code....

Interesting that you want to use a format specifically meant for separating individual values with commas, but need to retain information with commas inside it.

A good way of doing this would be to make your own tokenizer and only parse information when a stack is empty.

When you encounter quotes, push it onto the stack and read characters contiguously, even if it is a comma.

When you encounter quotes again, pop the original quote off of the stack and let your custom tokenizer do its thing, like normal.