cannot correct the error

Jun 17, 2011 at 2:07pm
#include<stdio.h>
#include<string.h>
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
char astr[51];
int lenth;
cout<<"\n Enter a string\n";
gets(astr);
lenth=strlen(astr);
puts(astr);
for(int i=1;i<lenth;i++)
{if(char astr[i]==" ")
{lenth--;
}
}
cout<<"\n The lenth of the string is"<<lenth<<"\n";
getch();
return 0;
}



error is cannot change char to char*
Jun 17, 2011 at 2:16pm
closed account (S6k9GNh0)
This is the articles section. Why. Can you not read? That might affect your programming...
Jun 17, 2011 at 2:33pm
This shouldn't be in this section. go to "beginners" but now that it's already posted. you need to do exactly that. change char to char*

 
char* astr[51];


EDIT:
Read up on strings. They are far more powerful than char* arrays
http://cplusplus.com/reference/string/string/string/
Last edited on Jun 17, 2011 at 2:35pm
Jun 17, 2011 at 2:59pm
This is the articles section. Why. Can you not read? That might affect your programming...

This is rude. Why. Can you not be polite? That might affect your interaction with people on this forum...

-Albatross
Last edited on Jun 17, 2011 at 9:17pm
Jun 17, 2011 at 4:53pm
closed account (S6k9GNh0)
O come on! We get this what, 2 or 3 times a day? Is it that difficult? Even for a non-English speaking person, they could at least look up the word "Article". What attracts them to "Articles" over General C++ Programming? Why should I take the time to help the OP when they can't take the time to post in the correct section. I think it's rude they post in the Articles section when it doesn't belong there. I'm blunt and honest but I have manners which are for a time and place. I don't think that place and time is here. They generally don't care to read the rules, and then they get pissed off when you don't help them or you ask them "politely" to use code tags for the millionth time (or just ignore you). It's like walking into America giving everyone the finger unknowingly saying "Fuck you". He doesn't know any better but he's still giving everyone the finger. There's precautions against this and he ignored them completely.
Last edited on Jun 17, 2011 at 5:09pm
Jun 17, 2011 at 7:09pm
Remember still be polite. We don´t want to give bad impression, right?

Welcome aboard, simplyjustin, you should´ve checked this one out before posting:
http://www.cplusplus.com/forum/articles/5/

Good luck and I hope you make yourself comfortable here.
Jun 18, 2011 at 6:30am
sorry i am new to this......thanks for telling me .....
Jul 11, 2011 at 8:14am
The error is at line
if(char astr[i]==" ")

first use ' ' to compare the single space
second use (char) for type cast

if((char) astr[i]==' '
)

Thanks
Madan
Last edited on Jul 11, 2011 at 8:14am
Topic archived. No new replies allowed.