You are returning saved
which is of type char *
, so declare you're function returning char *
as,
char * str_cpy(char *d, const char *s)
Вопрос
I need to implement the strcpy
source in C.
I dont understand why am i have this eror in line 15 (in the line- "return saved;"):
Error: return value type does not match function type
this is the full source:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
char str_cpy(char *d, const char *s)
{
char *saved = d;
while (*s)
{
*d++ = *s++;
}
*d = 0;
return saved; // line 15. here the eror
}
int main(int argc, char *argv[])
{
}
Решение
You are returning saved
which is of type char *
, so declare you're function returning char *
as,
char * str_cpy(char *d, const char *s)
Другие советы
You declared your function to return char
and you return char*
.
Change the function signature to return char*
.
char* str_cpy(char *d, const char *s)