fork download
  1. /* server */
  2. char buf[256];
  3. size_t len;
  4.  
  5. len = strlen(ent->d_name);
  6. sprintf(buf, "%zu%s", len, ent->d_name);
  7.  
  8. //bufの中身はパス名がtest.txtなら 8test.txt
  9.  
  10. write(sock, buf, strlen(buf));
  11.  
  12. /* client */
  13. char buf[256];
  14. size_t len;
  15. read(sock, buf, sizeof(char)); //ヘッダ情報だけ取得
  16. len = atoi(buf);
  17. memset(buf, '/0', sizeof(buf));
  18. read(sock, buf, len) ;
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:3:1: error: unknown type name 'size_t'
size_t len;
^
prog.c:5:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
len = strlen(ent->d_name);
^
prog.c:5:7: warning: implicitly declaring library function 'strlen' with type 'unsigned int (const char *)'
len = strlen(ent->d_name);
      ^
prog.c:5:7: note: include the header <string.h> or explicitly provide a declaration for 'strlen'
prog.c:5:14: error: use of undeclared identifier 'ent'
len = strlen(ent->d_name);
             ^
prog.c:6:14: error: expected identifier
sprintf(buf, "%zu%s", len, ent->d_name);
             ^
prog.c:6:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
sprintf(buf, "%zu%s", len, ent->d_name);
^
prog.c:6:1: warning: incompatible redeclaration of library function 'sprintf' [-Wincompatible-library-redeclaration]
prog.c:6:1: note: 'sprintf' is a builtin with type 'int (char *, const char *, ...)'
prog.c:10:24: error: expected ')'
write(sock, buf, strlen(buf));
                       ^
prog.c:10:6: note: to match this '('
write(sock, buf, strlen(buf));
     ^
prog.c:10:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
write(sock, buf, strlen(buf));
^
prog.c:10:7: error: a parameter list without types is only allowed in a function definition
write(sock, buf, strlen(buf));
      ^
prog.c:14:1: error: unknown type name 'size_t'
size_t len;
^
prog.c:15:17: error: expected identifier
read(sock, buf, sizeof(char)); //ヘッダ情報だけ取得
                ^
prog.c:15:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
read(sock, buf, sizeof(char)); //ヘッダ情報だけ取得
^
prog.c:16:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
len = atoi(buf); 
^
prog.c:16:7: warning: implicit declaration of function 'atoi' is invalid in C99 [-Wimplicit-function-declaration]
len = atoi(buf); 
      ^
prog.c:16:7: error: initializer element is not a compile-time constant
len = atoi(buf); 
      ^~~~~~~~~
prog.c:17:13: error: expected identifier
memset(buf, '/0', sizeof(buf));
            ^
prog.c:17:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
memset(buf, '/0', sizeof(buf));
^
prog.c:17:1: warning: incompatible redeclaration of library function 'memset' [-Wincompatible-library-redeclaration]
prog.c:17:1: note: 'memset' is a builtin with type 'void *(void *, int, unsigned int)'
prog.c:18:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
read(sock, buf, len) ;
^
prog.c:18:6: error: a parameter list without types is only allowed in a function definition
read(sock, buf, len) ;
     ^
11 warnings and 10 errors generated.
stdout
Standard output is empty