Adrita

lab 10

May 4th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. int main(int argc,char *argv[])
  4. {
  5. FILE *fp,*fp1;
  6. int i,len,j,wcount=0,ncount=0,m,k;
  7. char s[1000];
  8. fp1=fopen("newtext.txt","w");
  9. for(i=1; i<argc; i++)
  10. {
  11. fp=fopen(argv[i],"r");
  12. while(fgets(s,50,fp)!=NULL)
  13. {
  14. len=strlen(s);
  15. m=0;
  16. for(j=0;j<=len;j++)
  17. {
  18. if(s[j]==' '||s[j]=='\n'||s[j]=='0/'||s[j]==EOF)
  19. {
  20. if(s[j-1]>='A'&&s[j-1]<='Z'||s[j-1]>='a'&&s[j-1]<='z')
  21. {
  22. wcount++;
  23. printf("word #%d : ",wcount);
  24. fprintf(fp1,"word #%d : ",wcount);
  25. for(k=m;k<j;k++)
  26. {
  27. printf("%c",s[k]);
  28. fprintf(fp1,"%c",s[k]);
  29. }
  30. printf("\n");
  31. fprintf(fp1,"\n");
  32. }
  33. else if(s[j-1]>='0'&&s[j-1]<='9')
  34. {
  35. ncount++;
  36. printf("number #%d : ",ncount);
  37. fprintf(fp1,"number #%d : ",ncount);
  38. for(k=m;k<j;k++)
  39. {
  40. printf("%c",s[k]);
  41. fprintf(fp1,"%c",s[k]);
  42. }
  43. printf("\n");
  44. fprintf(fp1,"\n");
  45. }
  46. m=j+1;
  47. }
  48. }
  49.  
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment