Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,564 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,642 people online right now. Registration is fast and FREE... Join Now!




related to pointers

 
Reply to this topicStart new topic

related to pointers

garima
29 Oct, 2007 - 09:42 PM
Post #1

New D.I.C Head
*

Joined: 9 Oct, 2007
Posts: 46


My Contributions
i know i am posting it again but i am not getting any suggestion regarding the following coding....now i need to do this one using pointers::

CODE
#include <iostream.h>
#include <string.h>
void main()
{
     char str[20], str2[20];
     int a = 0;
     cin.get(str2, 20);
     strcpy(str,"");
     for(int b = 0; b < 20; b++)
     {
          if(str2[b] != ' ')
          {
               str[a] = str2[b];
               a++;
          }
     }
     a = 0;
     cout << str;
}

User is offlineProfile CardPM
+Quote Post

harshakirans
RE: Related To Pointers
29 Oct, 2007 - 10:01 PM
Post #2

D.I.C Head
Group Icon

Joined: 26 Apr, 2006
Posts: 122



Thanked: 3 times
Dream Kudos: 150
My Contributions
This should serve your purpose..


CODE

#include<iostream.h>
#include<string.h>

void main()
{

char str[30]="harsha",str2[20]="kiran";
int len;
char*ptr,*ptr2;
ptr2=str2;
ptr=str;
len=strlen(str);
ptr=ptr+len;
ptr--;
while(*ptr2!='\0')
{
*ptr++=*ptr2++;
}
*ptr='\0';
cout<<str;

}


This post has been edited by harshakirans: 29 Oct, 2007 - 10:01 PM
User is offlineProfile CardPM
+Quote Post

garima
RE: Related To Pointers
30 Oct, 2007 - 01:01 AM
Post #3

New D.I.C Head
*

Joined: 9 Oct, 2007
Posts: 46


My Contributions
please tel me what is the function of this line in your coding and what is the reason of using it....i didnt got it...
CODE

ptr=ptr+len;

User is offlineProfile CardPM
+Quote Post

garima
RE: Related To Pointers
30 Oct, 2007 - 01:36 AM
Post #4

New D.I.C Head
*

Joined: 9 Oct, 2007
Posts: 46


My Contributions
i now got it...thanks
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 10:14PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month