fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int width = 10;
  5. int height = 10;
  6. unsigned char *pdata = new unsigned char[width*height*4];
  7. unsigned char *rgbData = new unsigned char[width*height*3];
  8.  
  9. for(int i = 0; i < height;i++ )
  10. {
  11. for(int j = 0;j < width;j++)
  12. {
  13. unsigned char d = pdata + (i*width*4 + j*4);
  14. memcpy(rgbData + (i*width*3 + j*3),d,3);
  15. }
  16. }
  17.  
  18. return 0;
  19. }
  20.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘main’:
prog.c:6:24: error: ‘new’ undeclared (first use in this function)
 unsigned char *pdata = new unsigned char[width*height*4];
                        ^~~
prog.c:6:24: note: each undeclared identifier is reported only once for each function it appears in
prog.c:6:28: error: expected ‘,’ or ‘;’ before ‘unsigned’
 unsigned char *pdata = new unsigned char[width*height*4];
                            ^~~~~~~~
prog.c:7:30: error: expected ‘,’ or ‘;’ before ‘unsigned’
 unsigned char *rgbData = new unsigned char[width*height*3];
                              ^~~~~~~~
prog.c:13:22: warning: initialization makes integer from pointer without a cast [-Wint-conversion]
    unsigned char d = pdata +  (i*width*4 + j*4);
                      ^~~~~
prog.c:14:4: warning: implicit declaration of function ‘memcpy’ [-Wimplicit-function-declaration]
    memcpy(rgbData +  (i*width*3 + j*3),d,3);
    ^~~~~~
prog.c:14:4: warning: incompatible implicit declaration of built-in function ‘memcpy’
prog.c:14:4: note: include ‘<string.h>’ or provide a declaration of ‘memcpy’
prog.c:14:40: warning: passing argument 2 of ‘memcpy’ makes pointer from integer without a cast [-Wint-conversion]
    memcpy(rgbData +  (i*width*3 + j*3),d,3);
                                        ^
prog.c:14:40: note: expected ‘const void *’ but argument is of type ‘unsigned char’
stdout
Standard output is empty