problem in program for counting no of chars using pointers


Posted on 16th Feb 2014 07:03 pm by admin

Hi all, I was trying to make a program which counts number of chars in a string using concpt of pointers. Following is the code:

#include
#include
void main()
{
char *ptr1;
int ctr=0;
clrscr();

printf("Enter the string");
gets(ptr1);
while(1)
{

if(*ptr1!='/O')

{ *++ptr1; // *ptr1++;
ctr++;}
if(*ptr1 ='')
{
break;}
}
printf("Total chars are %d",ctr+1);
getch();
}

Above program compiles w/o errors but gives 2 warnings :
Line 14: Constant out of range in comparison.
Line 18: Possibly incorrect assignment.

I think I code it perfectly and I fail to interpret these warnings.
Note: If I execute the program ignoring the warning then once I pass the string the system comes to an halt and to come out I have to press ctrl+Pause break.
Pls help me to fix the error.....

Thanks

No comments posted yet

Your Answer:

Login to answer
229 Like 34 Dislike
Previous forums Next forums
Other forums

Email/MMS to Site
Hey guys. I'm looking for a way for a user to upload images and/or text via their cell phones. It

Pre-Fill out a PHP form...??
This is for work actually (geek squad). We have to fill out this online php form at work over and ov

rookie looking for help coding a CSS form with PHP
I'm trying to figure out how to add PHP code to my xhtml form so that it is a working form embedded

Grouping and sorting results
Please help with this query.

I have 2 tables in a database, countires and cities. states look

Php If in MySql query (hiding labels if a field is empty)
Okay, I've been trying to do this for a while, and I'm finally going to ask for help so I can get th

Doubles are giving me problems
Ok so, first of all i made a double = 0.05, but when running the debugger it shows up as 0.04999. I

Simple Variable Question
Hi everyone.... again,

I am really getting into php still. Learning more every day. I love it

SELECT * FROM users WHERE Users are not in Blocked
How do I select all users from users table where there users_id is not stored in the block table

Can't find the problem (no error message)!
OK, here's the deal. This code is really weirdly formatted (sorry!) and hard to understand, so I'm g

array help
Does anyone know how to require 10 text fields for individual grades and output class average? (10 p

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash