المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : كيف يتغل البرنامج



toyyo
17-12-2004, 05:32 PM
#include <iostream.h>

void mystery1(char *,const char *);

int main ()
{
char string1[80];
char string2[80];

cout<<"enter two string :";
cin>>string1>>string2;
mystery1(string1,string2);
cout<<string1<<endl;

return 0;

}

void mystery1(char *s1, const char *s2)
{
while(*s1 != '\0')
++s1;

for(;*s1=*s2;s1++,s2++)
;
}

كيف هذا البرنامج يشتغل ممكن حد يشرح لي ,,, وشكرا ,,,

wcw
18-12-2004, 10:55 PM
اخوي ممكن تخبرني وش المطلوب للبرنامج واساعدك
لان الكود مادري وش المقصود
من البرنامج حيرني

amgadpasha
22-12-2004, 05:25 PM
ok, this is a really nice piece of code..it could have been writen in much simpler way
mainly it concatenates two strings together
it reads two strings, pass their address to a function(which is the address of the first charcter of th string, now the function increaments the address of the first string untill it reaches the end of th word(this is th while loop) in the for loop, it simply copies the second string to the first string charcter by charcter
so the end result is that the first string contains both words beside each other

Wolf Sniper
22-12-2004, 06:16 PM
ok, this is a really nice piece of code..it could have been writen in much simpler way
mainly it concatenates two strings together
it reads two strings, pass their address to a function(which is the address of the first charcter of th string, now the function increaments the address of the first string untill it reaches the end of th word(this is th while loop) in the for loop, it simply copies the second string to the first string charcter by charcter
so the end result is that the first string contains both words beside each other
فقط أريد أن أضيف أن عمل الحلقة while في التابع mystery1 هو إيجاد المحرف الصفري في المصفوقة الأولى ( يعني نهاية الجملة ) و الحلقة for كما قال الأخ amgadpasha .