473,554 Members | 3,102 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 14815
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:...
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? ...
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...
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...
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...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main...
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...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
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...
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...
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...
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...

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.