Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

charatar pointer

This is a discussion on charatar pointer within the C and C++ forums, part of the Software Development category; #include "stdio.h" #include "string.h" void main() { char *str1="chet "; while(str1 != NULL) { printf("\nGO IN\n"); str1+=1; } } i am cheking NULL to come out of loop, but it ...

Go Back   Geeks Talk > Software Development > C and C++
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read
  #1 (permalink)  
Old 02-09-2009
Junior Member
 
Join Date: Dec 2008
Posts: 12
Thanks: 0
Thanked 2 Times in 2 Posts
chetanchauahan10 is on a distinguished road
charatar pointer

#include "stdio.h"
#include "string.h"
void main()
{

char *str1="chet ";
while(str1 != NULL)
{
printf("\nGO IN\n");
str1+=1;
}

}

i am cheking NULL to come out of loop, but it is going in infinite loop.
how it can come out and why it is not working
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-09-2009
Junior Member
 
Join Date: Feb 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
chaamurah is on a distinguished road
Re: charatar pointer

u have to use the condition

while(*str1!=NULL)
Reply With Quote
  #3 (permalink)  
Old 02-09-2009
Junior Member
 
Join Date: Feb 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
chaamurah is on a distinguished road
Re: charatar pointer

if u use while(str1!=NULL) u r checking the address , not the value at the address. that is the reason it is going to infinite loop
Reply With Quote
  #4 (permalink)  
Old 02-11-2009
Junior Member
 
Join Date: Feb 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
subraybhat is on a distinguished road
Re: charatar pointer

Change it to while(*str1!=NULL)
Reply With Quote
  #5 (permalink)  
Old 02-15-2009
Junior Member
 
Join Date: Dec 2008
Posts: 12
Thanks: 0
Thanked 2 Times in 2 Posts
chetanchauahan10 is on a distinguished road
Re: charatar pointer

yaa,,
Thanks
After posting the question, same clicked to me.
Reply With Quote
Reply

  Geeks Talk > Software Development > C and C++

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Pointer---? amaresh_83 C and C++ 6 03-22-2009 03:14 AM
Pointer Question bee896 C and C++ 3 02-14-2009 04:15 PM
far pointer anshu19 C and C++ 0 11-20-2008 10:47 PM
far pointer jaiprabuk C and C++ 0 05-27-2008 01:56 AM
Delegate and pointer Geek_Guest VB.NET 1 09-27-2007 03:21 AM


All times are GMT -4. The time now is 02:06 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2005 - 2010 GeekInterview.com. All Rights Reserved