excluding characters

This is a discussion on excluding characters within the C Programming forums, part of the General Programming Boards category; hey everyone I was wondering how do I take the \n out of a string which I received with fgets
...

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

Something tells me that you have been immersed in PHP code these days.

Grr... ironically, no, I am immersed in Python these days. PHP was from long ago. But yes, it should be strchr(). Speaking of this, I am quite irritated by C-like additions to the PHP built-in functions. They should have gone for proper names from the start.

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

I think the name of PHP strchr() is just evil for any C programmers... Why the heck didn't they call it strstr()?

As implied by my previous post, I agree that strchr() and strstr() are rather "evil" names, but at least the tradition of such crazy abbreviations is more or less consistent in the C standard library. Obviously, they cannot call strchr strstr since they are different functions... plus naming strchr strstr would be even crazier and harder to remember.

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

You need to be absolutely clear on what you are trying to do. Do you want to delete all of them? Replace all of them... with what?

Originally Posted by xniinja

but at the part that the user types something it might delete the commas inside, and I have to delete the quotes so I was thinking something like this

Inside what? What might delete the commas inside that thing? The user? The program? If you delete the quotes, how does that fix the problem?

For example, you might say that this is some sample input:

Code:

number,number,number,"the user types something here"

Maybe you want to tokenise the input based on the comma, i.e., from the above input, you would get four strings consisting of the three numbers and '"the user types something here"'. The problem is that if '"the user types something here"' was '"hello,world"', you might end up with five strings instead: the three numbers, and '"hello' and then 'world"'. So, how can such commas within double quotes be ignored in the tokenisation?

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

I made it so the num1 (in my code) will be incrimented by 1 every time it removes a comma, so once it hits three it doesn't delete another comma, but I have to format it like this because it has to be readable by excel. (it is a .xls file)

number,number,number,"the user types something here"

so all I am asking is how do I do the part that I said in the above code, this part:

Code:

while(get one character from the buff1 and put it into a variable called character)

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

EDIT:
You might notice that I edited my code because the example in which I accommodated your use of the character variable did not increment the pointer. It would be simpler to just use the pointer directly, but I have edited to use another pointer in case buff1 is actually an array.

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.