fork(1) download
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. int main(int argc,char *argv[])
  5. {
  6. if(argc < 2)
  7. printf("Very few arguments : see usage - wc --help\n");
  8. if(argc > 3)
  9. printf("Too many arguments : see usage - wc --help\n");
  10. int c=0,l=0,w=0;
  11. if(argc==2)
  12. c=l=w=1;
  13. char *fname;
  14. // if there are arguments
  15. int i;
  16. for(i=0;i<argc;i++)
  17. {
  18. if(strncmp(argv[i],"-c")==0)
  19. c=1;
  20. else if(strncmp(argv[i],"-w")==0)
  21. w=1;
  22. else if(strncmp(argv[i],"-l")==0)
  23. l=1;
  24. else if(strncmp(argv[i],"wc")==0)
  25. continue;
  26. else
  27. fname = arv[i];
  28. }
  29. File *fp ;
  30. fp = fopen(fname,"r");
  31. char c;
  32. char ar[100];
  33. int cl=0,cw=0,cc=0,p=0;
  34. while( (c=getc(fp))!= 'EOF')
  35. {
  36. if(c=="\n")
  37. cl++;
  38. else if(c==' ')
  39. {
  40. if(strncmp(ar,"\0")!=0)
  41. cw++;
  42. for(i=0;i<100;i++)
  43. ar[i]='\0';
  44. p=0;
  45. }
  46. else
  47. {
  48. ar[p++]=c;
  49. cc++;
  50. }
  51. }
  52. fclose(fp);
  53. return 0;
  54.  
  55. }
  56.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function 'main':
prog.c:18:36: error: macro "strncmp" requires 3 arguments, but only 2 given
             if(strncmp(argv[i],"-c")==0)
                                    ^
prog.c:18:37: warning: the comparison will always evaluate as 'false' for the address of 'strncmp' will never be NULL [-Waddress]
             if(strncmp(argv[i],"-c")==0)
                                     ^
prog.c:20:41: error: macro "strncmp" requires 3 arguments, but only 2 given
             else if(strncmp(argv[i],"-w")==0)
                                         ^
prog.c:20:42: warning: the comparison will always evaluate as 'false' for the address of 'strncmp' will never be NULL [-Waddress]
             else if(strncmp(argv[i],"-w")==0)
                                          ^
prog.c:22:41: error: macro "strncmp" requires 3 arguments, but only 2 given
             else if(strncmp(argv[i],"-l")==0)
                                         ^
prog.c:22:42: warning: the comparison will always evaluate as 'false' for the address of 'strncmp' will never be NULL [-Waddress]
             else if(strncmp(argv[i],"-l")==0)
                                          ^
prog.c:24:41: error: macro "strncmp" requires 3 arguments, but only 2 given
             else if(strncmp(argv[i],"wc")==0)
                                         ^
prog.c:24:42: warning: the comparison will always evaluate as 'false' for the address of 'strncmp' will never be NULL [-Waddress]
             else if(strncmp(argv[i],"wc")==0)
                                          ^
prog.c:27:21: error: 'arv' undeclared (first use in this function)
             fname = arv[i];
                     ^
prog.c:27:21: note: each undeclared identifier is reported only once for each function it appears in
prog.c:29:5: error: unknown type name 'File'
     File *fp ;
     ^
prog.c:30:8: warning: assignment from incompatible pointer type
     fp = fopen(fname,"r");
        ^
prog.c:31:10: error: conflicting types for 'c'
     char c;
          ^
prog.c:10:9: note: previous definition of 'c' was here
     int c=0,l=0,w=0;
         ^
In file included from prog.c:1:0:
prog.c:34:20: warning: passing argument 1 of '_IO_getc' from incompatible pointer type
     while( (c=getc(fp))!= 'EOF')
                    ^
In file included from /usr/include/stdio.h:74:0,
                 from prog.c:1:
/usr/include/libio.h:434:12: note: expected 'struct _IO_FILE *' but argument is of type 'int *'
 extern int _IO_getc (_IO_FILE *__fp);
            ^
prog.c:34:27: warning: multi-character character constant [-Wmultichar]
     while( (c=getc(fp))!= 'EOF')
                           ^
prog.c:36:13: warning: comparison between pointer and integer
         if(c=="\n")
             ^
prog.c:36:13: warning: comparison with string literal results in unspecified behavior [-Waddress]
prog.c:40:31: error: macro "strncmp" requires 3 arguments, but only 2 given
             if(strncmp(ar,"\0")!=0)
                               ^
prog.c:40:32: warning: the comparison will always evaluate as 'true' for the address of 'strncmp' will never be NULL [-Waddress]
             if(strncmp(ar,"\0")!=0)
                                ^
prog.c:52:12: warning: passing argument 1 of 'fclose' from incompatible pointer type
     fclose(fp);
            ^
In file included from prog.c:1:0:
/usr/include/stdio.h:237:12: note: expected 'struct FILE *' but argument is of type 'int *'
 extern int fclose (FILE *__stream);
            ^
prog.c:32:10: warning: variable 'ar' set but not used [-Wunused-but-set-variable]
     char ar[100];
          ^
stdout
Standard output is empty