![]() |
| | #1 |
| Registered User Join Date: Apr 2009
Posts: 10
| I want to write a code which takes an array of 20 characters and deletes all spaces between characters, it should leave only letters. For example: input :a b c d e I want to make it : abcde I wrote this code, but it didn't change anything: Code: #include <stdio.h>
int main ()
{
int i;
char a[21];
gets(a);
for(i = 0; i < 20; i++)
{
if(a[i] == 8 || a[i] == 9)
{a[i]= a[i+1];
i--;}
else continue;
}
printf("%s", a);
printf("\n");
return 0;
}
Can you help me with that? Thanks... |
| bahada is offline | |
| | #2 |
| Registered User Join Date: Apr 2009
Posts: 187
| your searching if a[i]==8 or 9 whish is back space or horiztal tab then you making i+1 to that a and minunsing i after that ii dunno why your doing that anyways ? why dont you try copy anything inside the string thats not space if(a[i]!=' '){continue your function here}? |
| elwad is offline | |
| | #3 |
| Registered User Join Date: Oct 2008 Location: TX
Posts: 1,262
| Code: if(a[i] == 8 || a[i] == 9) /* what is this statement supposed to do??? */ |
| itCbitC is offline | |
| | #4 |
| Registered User Join Date: Apr 2009
Posts: 10
| to catch if the character is a space or not (backspace and horizontal tab) |
| bahada is offline | |
| | #5 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| ' ' == 32 The other complication is that "i--" is not sufficient to compress the string.
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS |
| MK27 is offline | |
| | #6 |
| Registered User Join Date: Oct 2008 Location: TX
Posts: 1,262
| Then use the character constant instead of its decimal value which depends on the underlying character set. |
| itCbitC is offline | |
| | #7 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
|
__________________ If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. Up to 8Mb PlusNet broadband from only £5.99 a month! |
| Salem is offline | |
| | #8 | |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| Salem is being mean! There is nothing wrong with the OP. The one and only reply on Daniweb starts out with a completely moronic and incorrect analysis: Quote:
Chill out bahada.
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS | |
| MK27 is offline | |
| | #9 |
| Registered User Join Date: Apr 2009
Posts: 10
| I solved this problem in another way thanks, and I asked at first at daniweb but i couldn't get the answer for hours, then I asked here.. |
| bahada is offline | |
| | #10 |
| Registered User Join Date: Apr 2009 Location: Russia
Posts: 116
| function for deleting any character |
| c.user is offline | |
| | #11 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| > but i couldn't get the answer for hours, then I asked here Oh, but there are answers there. So now you're claiming it's urgent Don't go round spamming multiple forums in the mistaken belief that you're entitled to a 24/7 service wherever you go.
__________________ If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. Up to 8Mb PlusNet broadband from only £5.99 a month! |
| Salem is offline | |
| | #12 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| That is not spamming, and you are not obliged to answer questions...I think.
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS |
| MK27 is offline | |
![]() |
| Tags |
| array, character, delete, space, string |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Inheritance Hierarchy] User Input on program with constructors. How ? | chandreu | C++ Programming | 8 | 04-25-2008 02:45 PM |
| Inheritance Hierarchy for a Package class | twickre | C++ Programming | 7 | 12-08-2007 04:13 PM |
| Custom String class gives problem with another prog. | I BLcK I | C++ Programming | 1 | 12-18-2006 03:40 AM |
| Compile Error that i dont understand | bobthebullet990 | C++ Programming | 5 | 05-05-2006 09:19 AM |
| problems in removing white spaces from string of text | monil | C Programming | 1 | 03-08-2005 12:02 PM |