how can i ermove special characters from my string
example:
i havechar *str=" cprogramming\n";
how can i remove "\n".
any function for removing special characters
thank u
sree
how can i ermove special characters from my string
example:
i havechar *str=" cprogramming\n";
how can i remove "\n".
any function for removing special characters
thank u
sree
how can i ermove special characters from my string
example:
i havechar *str=" cprogramming\n";
how can i remove "\n".
any function for removing special characters
thank u
sree
This is a nice function posted by Cactus Hugger, a while ago. It removes blank spaces from a string. I'll bet you could easily figure out how to alter this function to remove any ascii value you sent to the function as another parameter:
If you get stuck, fear not - there are all kinds of ways of doing this function. Post up your problem when and if your function has errors you need help with.Code:void remove_spaces(char *string) { char *read, *write; for(read = write = string; *read != '\0'; ++read) { /* edit: or if(!isspace(*read)), see swoopy's suggestion below */ if(*read != ' ') { *(write++) = *read; } } *write = '\0'; }
If you're trying to remove the newline that is usually present in strings read by fgets(), there are many ways to do it. The favourite seems to be this:
Do a board search and you'll find many other ways. Here's another related thread: http://cboard.cprogramming.com/showthread.php?t=70320Code:#include <stdio.h> #include <string.h> char line[BUFSIZ], *p; fgets(line, sizeof(line), stdin); if((p = strchr(line, '\n'))) *p = 0;
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Warning.....
Do not try to alter the above string. If you want szString to be altered, it should be declared like this:Code:char *szString = "Some type of string.\n";
Internally, the two forms are very different. One major difference is that the string could very well be in read-only memory, which can cause severe problems for you later on.Code:char szString[] = "Some type of string.\n";
that's why the first string should be declared as const char* in the first place
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler