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

Passing Variables
What I'm wanting to do is when the user clicks on Arenas it will know the name of the country it's w

Splitting Attributes
SQL> SELECT I_NAME, substr(I_NAME,1,instr(I_NAME,'O')) "First part",

substr(I_NAME, IN

Help with usergroups? prolly really quick
So were coding our own forums for a game system we made an we have the users level setup but now I n

Function module "DPS_CHECK_TABLE_EXISTS" not found (after OSS 1422843 impl)
Dear All,

I implemented Note OSS 1422843.

When i execute the new report RSPO20

Calander layout
Hi i know this sounds like a simple question but i cant find the answer to it anywhere i have added

How to Create a Dynamic table
col1 col2 date1 date2 date3 date4..........
a b v1 v2 v3 v4

Multi Dimensional Array Append
Hi Guys

I have a function that returns a multidimentional array eg

$result = functio

isset undefined variable
Hi all,

Hope someone can point out the obvious. I've a log in script, if you dont enter a use

Upload, SSL and more php help
I recently just installed a ssl cert and do i use https for the whole site or just for the checkout.

Displaying image pathname instead of image
Hello

Im trying to upload and then display images from a mysql database - Its only basic and

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