how to remove the non keyboard specialcharecters from string
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
-
- Participant
- Posts: 70
- Joined: Thu Nov 09, 2006 2:14 am
This is a parallel routine that i wrote. And meets your requirement.
Hope this helps.
Code: Select all
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char* DeleteChars(char *inputstring)
{
char *OutPut= (char *)malloc (sizeof(char *));
int length = 0;
int StringLength = strlen(inputstring);
if (length == 0)
OutPut[length] = '\0';
else
{
while(*inputstring)
{
if ((*inputstring>= 32) && (*inputstring<= 126))
{
OutPut[length] = *inputstring;
length++;
}
inputstring++;
}
OutPut[length] = '\0';
}
return OutPut;
free(OutPut);
}
Last edited by BugFree on Thu Mar 27, 2008 5:51 am, edited 1 time in total.
Ping me if I am wrong...
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Just curious; where does the variable called "i" get its value? You test it in
Code: Select all
(i == 0)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ray.wurlod wrote:Just curious; where does the variable called "i" get its value? You test it in...Code: Select all
(i == 0)
Copy paste error. I changed it in the post. Tested it and it is working.
Ping me if I am wrong...
I remember building something like this a while back. Check the following post for reference.
viewtopic.php?t=108011&postdays=0&posto ... g&start=15
Bugfree, get rid of free(OutPut); from you code as it will never be executed. The engine will take care of freeing the memory.
viewtopic.php?t=108011&postdays=0&posto ... g&start=15
Bugfree, get rid of free(OutPut); from you code as it will never be executed. The engine will take care of freeing the memory.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.