Mit der Anweisung printf printf("new s3 string (in locate function) is \"%s\" \n",s3)
arbeitet CodeWie ändert printf den Rückgabewert einer Funktion?
richtig, aber wenn printf("new s3 string (in locate function) is \"%s\" \n",s3)
kommentiert wird, kehrt der Code null
wie wird printf
den return
Wert zu beeinflussen?
#include <stdio.h>
#include <string.h>
char * locate(char * s1,char * s2,int index)
{
printf("s1 string is \"%s\" \n",s1);
printf("s2 string is \"%s\" \n",s2);
int i=0,j=0, k;
char s3[100];
while(i<=index)
{
s3[i]=s1[i];
i++;
}
k=i;
while(s2[j]!='\0')
{
s3[i]=s2[j];
i++; j++;
}
while(s1[k]!='\0')
{
s3[i]=s1[k];
i++;k++;
}
s3[i]='\0';
//printf("new s3 string (in locate function) is \"%s\" \n",s3);
return ((char *)s3);
}
int main(void)
{
char * s1="my name shwetha";
char * s2="is ";
s1=locate(s1,s2,7);
printf("Final Inserted string S1 is \"%s\" \n",s1);
return 0;
}
Mögliches Duplikat von [Rückgabe einer lokalen Variablen aus Funktion in C] (http://stackoverflow.com/questions/4824342/returning-a-local-variable-from-function-in-c) –