fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char *copyStr(int n,const char *str);
  6.  
  7. int main(void) {
  8. char srcStr[20],dupStr[80];
  9. int n;
  10. printf("enter a string(len<20):");
  11. scanf("%s",&srcStr);
  12. printf("n(n<=4)=");
  13. scanf("%d",&n);
  14. dupStr=copyStr(n,srcStr);
  15. printf("%s",dupStr);
  16. return 0;
  17. }
  18.  
  19. char *copyStr(int n,const char *str){
  20. int i,j,len=strlen(str);
  21. char array[80];
  22. for(i=0;i<n;i++){
  23. for(j=0;j<len;j++){
  24. array[len*i+j]=str[j];
  25. }
  26. }
  27. array[len*i]='\0';
  28. return *array;
  29. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function 'main':
prog.c:11:8: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[20]' [-Wformat=]
  scanf("%s",&srcStr);
        ^
prog.c:14:8: error: assignment to expression with array type
  dupStr=copyStr(n,srcStr);
        ^
prog.c: In function 'copyStr':
prog.c:28:9: warning: return makes pointer from integer without a cast [-Wint-conversion]
  return *array;
         ^
stdout
Standard output is empty