strcpy function does not work on Linux [closed]

1
#include <stdio.h>
#include <string.h>

void envia(char* pdados);

int main()
{
char* link[1000];
strcpy(link,"http://site.com/data.php?dados=");

char* dados = "name";

strcat(link,dados);

//printf("%s\n",link);
envia(link);
}

void envia(char *pdados){
printf("%s\n",pdados);

char comando[2000];
sprintf(comando, "curl %s >> /dev/null", pdados);
system(comando);
}

ERROR:

manda.c: In function ‘main’:
manda.c:9:2: warning: passing argument 1 of ‘strcpy’ from incompatible pointer type [enabled by default]
  strcpy(link,"http://site.com/data.php?dados=");
  ^
In file included from manda.c:2:0:
/usr/include/string.h:129:14: note: expected ‘char * __restrict__’ but argument is of type ‘char **’
 extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
              ^
manda.c:13:2: warning: passing argument 1 of ‘strcat’ from incompatible pointer type [enabled by default]
  strcat(link,dados);
  ^
In file included from manda.c:2:0:
/usr/include/string.h:137:14: note: expected ‘char * __restrict__’ but argument is of type ‘char **’
    
asked by anonymous 10.12.2017 / 02:28

3 answers

1

As a link was declared as a pointer (of a char array), so the link variable (or link [0]) represents a pointer pointer (char **), since both alone (without the pointer statement) indicate a pointer to the beginning of the char array. So instead of using char* link[1000] use char link[1000] . Because the strcpy function gets a char * and not a char **, the same goes for strcat.

    
10.12.2017 / 02:50
0

I changed the data type of the function, and now it's working, thanks for the help

void envia(char *pdados)
{
    char* dados = pdados;

    char* resultado;
    size_t  len;

    len = (size_t)("http://site.com/data.php?dados=");
    resultado = malloc((len + 1) * sizeof(char));

    strncpy(resultado, "site.com/data.php?dados=", len);

    strcat(resultado,dados);
    //printf("%s\n",resultado);

    char comando[2000];
    sprintf(comando, "curl -s %s >> /dev/null &", resultado);
    system(comando);
}
    
10.12.2017 / 12:45
-1
#include <stdio.h>
#include <stdlib.h>

void envia(char *pdados) {
   char comando[1000];
   sprintf(comando, "curl -s '%s%s' > /dev/null",     
             "http://site.com/data.php?dados=", pdados);
   system(comando);
}

int main(){
   envia("aaa");
   return 0;
}
    
13.12.2017 / 17:44