- برچسب ها: آرایه، array، سه بعدی، 3 بعدی، آرایه سه بعدی، 3d array، ضرب آرایه ها، ضرب آرایه 3 بعدی، سورس سی پلاس پلاس، سورس C++، سورس ساده،
برنامه ای که نحوه عملکرد دو تابع _strupr و _strlwr را نشان میدهد:
#include <string>
using namespace std;
void main()
{
char string[] = "The String to End All Strings!";
cout<<"Mixed:\n"<<string<<endl;
cout<<"Uper:\n"<<strupr(string)<<endl;
char* lwr_str=strlwr(string);
cout<<"Lower:\n"<<lwr_str<<endl;
}
//end
برنامه ای که یادآوری: نحوه عملکرد توابع strchr و strrchr را نشان میدهد:
#include <string>
using namespace std;
void main(void)
{
char ch='r';
char string[] =
"The quick brown dog jumps over the lazy fox";
char fmt1[] =
" 1 2 3 4 5";
char fmt2[] =
"12345678901234567890123456789012345678901234567890";
char* pdest;
int result;
cout<<"String to be searched: \n\t\t"<<string<<"\n";
cout<<"\t\t"<<fmt1<<"\n\t\t"<<fmt2<<"\n\n";
cout<<"Search char:\t"<<ch<<"\n";
/* Search forward. */
pdest=strchr(string, ch);
result=pdest - string + 1;
if( pdest != NULL )
cout<<"Result:\tfirst "<<ch
<<" found at position "<<result<<"\n\n";
else
cout<<"Result:\t"<<ch<<" not found\n";
/* Search backward. */
pdest=strrchr(string, ch);
result=pdest - string + 1;
if( pdest != NULL )
cout<<"Result:\tfirst "<<ch
<<" found at position "<<result<<"\n\n";
else
cout<<"Result:\t"<<ch<<" not found\n";
}
//end
- برچسب ها: strchr، strrchr، stringchr، string characters، رشته، تابع، جستجو، جستجو کاراکتر، جستجو رشته، سرچ،
برنامه ای که کاربرد تابع strlen را نشان میدهد. با اجرای این برنامه عدد 15 به عنوان طول رشته str چاپ میشود:
#include <string>
using namespace std ;
int main()
{
char str [16] = "how long am I ?";
int len ;
len = strlen(str) ;
cout<<str<<" is "<<len<<" characters long\n";
return 0;
}
//end
پیاده سازی تابع strrchr
{
for(int i=0;s[i];++i);
return i;
}
char *strrchr(const char *s,int c)
{
long i;
for(i=strlen(s)-1;i>=0 && s[i]!=(char)c;i--);
if(i<0)
return NULL;
else
return (char *)&s[i];
}
//end
پیاده سازی strncpy به دو صورت
صورت اول:
{
for(unsigned i=0;i<n && t[i]!='\0';i++)
s[i]=t[i];
for(;i<n;i++)
s[i]='\0';
return s;
}
//end
{
char *ts=s;
for(unsigned i=0;i<n && *t!='\0';i++,s++,t++)
*s=*t;
for(;i<n;i++,s++)
*s='\0';
return ts;
}
//end
پیاده سازی تابع strncat
{
const char *p=t;
unsigned i,j;
i=j=0;
while(s[i]!='\0')
i++;
while(j<n && (s[i++]=p[j++])!='\0');
if(p[j-1]!='\0')
s[i]='\0';
return s;
}
//end
پیاده سازی strcpy به دو صورت
{
int i=0;
while((s[i]=t[i])!='\0')
i++;
return s;
}
//end
{
char *ts;
ts=s;
while((*s=*t)!='\0')
{
s++;
t++;
}
return ts;
}
//end
- برچسب ها: strcpy، strcopy، string copy، رشته، کپی رشته ها، کپی، تابع،
پیاده سازی توابع strlen و strchr
{
for(int i=0;s[i];++i);
return i;
}
char *strchr(const char *s,int c)
{
unsigned i;
for(i=0;i<strlen(s) && s[i]!=(char)c;++i);
if(i==strlen(s))
return NULL;
else
return (char *)&s[i];
}
//end
- برچسب ها: string، strlen، strlenght، string lenght، strchr، strinhchr، رشته، تابع، function، پیاده سازی تابع،
پیاده سازی تابع strcat
{
unsigned i,j;
i=j=0;
while(s[i]!='\0')
i++;
while((s[i++]=t[j++])!='\0');
return s;
}
//end
- برچسب ها: تابع، strcat، رشته، تابع رشته ها، string، function، پیاده سازی تابع، شبیه سازی تابع،
تبلیغات
