Created
May 11, 2018 17:10
-
-
Save edenizk/cf40c1dd72c36e398469154ea7e4007b to your computer and use it in GitHub Desktop.
strings in C language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
unsigned scat(char *s, char *s2) | |
{ | |
int i,j; | |
for(i=0;s[i]!=0; i++); | |
s[i++]=32; | |
for(j=0;s2[j]!=0;j++){ | |
s[i]=s2[j]; | |
i++; | |
} | |
s[i]=0; | |
} | |
unsigned slen (char *s) | |
{ | |
int i; | |
for(i=0;s[i]!=0;i++); | |
return i; | |
} | |
char* create(char *s,char *s2) | |
{ | |
static char s3[100]; | |
s3[0]=0; | |
scat(s3,s); | |
scat(s3,s2); | |
printf(" "); | |
return s3; | |
} | |
int main() | |
{ | |
char str1[50]="Alice"; | |
char str2[]="dog"; | |
char str3[]="Peter",str4[]="Cat"; | |
char *st1,*st2; | |
st1=create(str1,str2); | |
printf("st1=%s\nst1=%p\nst2=%s\nst2=%p\n\n",st1,st1,st2,st2); | |
st2=create(str3,str4); | |
printf("st2=%s\nst2=%p\nst1=%p\n\n",st2,st2,st1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment