cannot correct the error

#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*
closed account (S6k9GNh0)
This is the articles section. Why. Can you not read? That might affect your programming...
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
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
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
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.
sorry i am new to this......thanks for telling me .....
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
Topic archived. No new replies allowed.