473,708 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

remove punctuation in C

7 New Member
can anyone help me write up a function to remove space, semicolons, etc?
Nov 21 '08 #1
15 14846
2,426 Recognized Expert Top Contributor
Do you have any suggestions for how you might recognize punctuation or space characters in a string?
Nov 21 '08 #2
7 New Member
so, i think when you are using the remove_punc function, you have to write the script so that it keeps in the characters, while removing the punctions.
Nov 21 '08 #3
671 Recognized Expert Contributor
so, i think when you are using the remove_punc function, you have to write the script so that it keeps in the characters, while removing the punctions.
Yes, presumably it’s why you called it a remove punctuation function, as opposed to retain punctuation function or something. We aren’t sure what your question is though. You requested help, but that’s not necessary. We are all here to help.

But what is your question?
Nov 21 '08 #4
7 New Member
I'm sorry. I have just started learning programming so I am trying to teach myself the basics with functions and strings.
My question is that how do i write something like "My name is Peter" and I get back "mynameispe ter" ?
How do i use the function?
Nov 21 '08 #5
2,426 Recognized Expert Top Contributor
I'm sorry. I have just started learning programming so I am trying to teach myself the basics with functions and strings.
My question is that how do i write something like "My name is Peter" and I get back "mynameispe ter" ?
How do i use the function?
First let's specify the interface to this function. It needs an input string and it needs to return a string. The input string is easy to handle: one of the function arguments is a pointer to the input string. I can think of three ways to handle the output string: (1) since the length of the output string can never be greater than the length of the input string, you can overwrite the input string; (2) you can malloc a buffer for the output string; and (3) the caller can pass you a buffer to use for the output string. Options (2) and (3) have failure modes (malloc can fail in #2; and the passed buffer can be too small in #3), so some method is needed to distinguish success from failure. Which of these sounds like what you want to do? I suggest you pick an interface and then create a corresponding function prototype.
Nov 21 '08 #6
671 Recognized Expert Contributor
My question is that how do i write something like "My name is Peter" and I get back "mynameispe ter" ?
There’s two aspects to that question. One is the issue of code: what exact code do you need to write. The other issue is the algorithm, which is partly independent of the language and code. How do you approach something like this algorithmically ? So you need to sit and think about algorithms. What data structure are you dealing with? How would you do the work on paper? What does pseudocode or plain English instructions for the algorithm look like? That’s your primary question.
Nov 21 '08 #7
19 New Member
I haven't done this in C but have done this in C++, java and C#.

psuedo code:

string someFunction(st ring string){
string str;
for(int i = 0 ; i<string.size( ) ; i++) {//loop through the main string passed in character by character
char j = string[i];
if(j>=65 && j<=90 || j>=97 && j<=122 || j == 32 || j>=48 && j<=57){ //these numbers are ascii values... 65-90 lowercase letter, 97-122 upper case letter , 48-57 numbers and 32 is spaces
str += string[i];

return str;

this is a c++ code... it may even compile. if called correctly....

by for string manupilations ascii values are the way to go!

i'm not a pro but this algorythm should work in c as well!

Nov 23 '08 #8
11,448 Recognized Expert MVP
No they are not.

kind regards,

Nov 23 '08 #9
19 New Member
why not??? what do you suggest?
Nov 23 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Lachlan Hunt | last post by:
Hi, I have recently downloaded and experemented with IBM HPR 3.0, and Opera 8 with text-to-speech, and have come to realise some fairly annoying issues regarding punctuation marks. I've found, that when a punctuation mark occurs directly after an element, both HPR and Opera 8 will read the punctuation mark. For example, the following: <p><abbr title="...">HTML</abbr> is an application of
by: Chris Leffer | last post by:
Hi. I am trying to define a regular expression that accepts letters and punctuation characters. I read something about Posix where I could use in order to accept all the punctuation characters, but I could not find how to add this to my expression. My expression is a simple . How can I make it accept all the punctuation characters also? Regards,
by: Anat | last post by:
Hi, I need a little help on performing string manipulation: I want to take a given string, and make certain words hyperlinks. For example: "Hello world, this is a wonderful day!" I'd like the words world & and day to be hyperlinks, therefore after my manipulation it should be: "Hello <a href=...>world</a>, this is a wonderful <a href=...>day</a>!" Using split method is not good, because splitting with regex each punctuation mark causes...
by: Tashfeen Bhimdi | last post by:
I'm trying to remove punctuation from a string with the following code: ---------------------------- #include <string> #include <algorithm> #include <cctype> .. using namespace std ..
by: joe | last post by:
hello i have a databse program that uses char arrays to output data to reports. I would like to remove all invalid characters from the array and replace them with a blank space. I have problems with ( ' return and some non ascii charcters. Any quick and dirty way to do this? thanks.
by: watcher00 | last post by:
Hi I'm a complete newbie at Perl and i was wondering if i can get some help completing an exercise i've come across. I need to count the punctuation marks from a text file and then output a list of all occurring punctuation marks with its frequency printed next to it. eg 2 hyphens 3 commas
by: kdsutaia | last post by:
hi! i m trying to do something like this. as I am doing tockenization. and wants to include all punctuation mark as tocken. if($punctuation){ grep {$p =~ m/$_/' '.$_.' '/g)} ("\.", "\%", "\'", "\\", "\", "\{", "\}", "\"", "\>", "\?", "\<", "\#", "\~", "\=", "\&", "\*", "\,", "\!", "\@", "\$", "\(", "\)", "\+", "\-", "\_", "\|", "\:", "\;", "\.", "\/", "\$", "\@", "\-", "\'", "\``"); }
by: Mike Copeland | last post by:
I have data I need to normalize - it's "name" data. For example, I have the following: "Watts, J.C." I wish to (1) parse the "first name" ("J.C.") and adjust it to "JC". Essentially, I want to remove the punctuation characters from the "first name" substring. I've looked at the basic_string in C++, but I can't find the functions that will _remove" character(s) from a value. There are operators that are helpful in finding the position...
by: Shiao | last post by:
Hello, I'm trying to build a regex in python to identify punctuation characters in all the languages. Some regex implementations support an extended syntax \p{P} that does just that. As far as I know, python re doesn't. Any idea of a possible alternative? Apart from manually including the punctuation character range for each and every language, I don't see how this can be done. Thank in advance for any suggestions.
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.