#include
#include
#include
#include
int main(int argc,const char *argv[])
{
char str1[20];
char str2[20];
printf("please enter str1:");
gets(str1);
printf("please enter str2:");
gets(str2);
int i=0;
for(i=0;str2[i]!='\0';i++)
{
str1[i]=str2[i];
}
str1[i]='\0';
puts(str1);
puts(str2);
return 0;
}
#include
#include
#include
#include
int main(int argc,const char *argv[])
{
char str1[20];
char str2[20];
printf("please enter str1:");
gets(str1);
printf("please enter str2:");
gets(str2);
int i,j;
for(i=0;str1[i]!='\0';i++);
for(j=0;str2[j]!='\0';j++)
{
str1[i+j]=str2[j];
}
str1[i+j]='\0';
puts(str1);
puts(str2);
return 0;
}
#include
#include
#include
#include
int main(int argc,const char *argv[])
{
char str[]="abcdefg";
int i;
for(i=0;str[i]!='\0';i++);
printf("%d",i);
return 0;
}
#include
#include
#include
#include
int main(int argc,const char *argv[])
{
char str1[20];
char str2[20];
printf("please enter str1:");
gets(str1);
printf("please enter str2:");
gets(str2);
int i=0;
while(str1[i]==str2[i])
{
if(str1[i]=='\0')
{
break;
}
i++;
}
if(str1[i]-str2[i]>0)
{
puts("str1>str2");
}
else if(str1[i]-str2[i]<0)
{
puts("str1
使用for循环代码:
#include
#include
#include
#include
int main(int argc,const char *argv[])
{
char str1[20];
char str2[20];
printf("please enter str1:");
gets(str1);
printf("please enter str2:");
gets(str2);
int i;
for(i=0;str1[i]==str2[i]!='\0';i++);
if(str1[i]-str2[i]>0)
{
puts("str1>str2");
}
else if(str1[i]-str2[i]<0)
{
puts("str1
#include
#include
#include
#include
int main(int argc,const char *argv[])
{
char str[20];
gets(str);
int i=0;
while(str[i]==' ')
{
i++;
}
int j=i,sum=0;
if(str[j]=='='||str[j]=='-')
{
i++;
}
while(str[i]>='0'&&str[i]<='9')
{
sum=sum*10+(str[i]-'0');
i++;
}
if(str[j]=='-')
{
sum=-sum;
}
printf("sum=%d",sum);
return 0;
}
将“hello”——>"olleh"
#include
#include
#include
#include
int main(int argc,const char *argv[])
{
char str[]="hello";
int i=0,j=strlen(str)-1;
while(i
将“study good good"——>"good good study"
#include
#include
#include
#include
int main(int argc,const char *argv[])
{
char str[]="study good good";
int i=0,j=strlen(str)-1;
while(i
#include
#include
#include
#include
int main(int argc,const char *argv[])
{
return 0;
}
运行结果: