Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5.  
  6. void wtf() {
  7. FILE *f = fopen("zborovi.txt", "w");
  8. char c;
  9. while((c = getchar()) != EOF) {
  10. fputc(c, f);
  11. }
  12. fclose(f);
  13. }
  14.  
  15. int main() {
  16. wtf();
  17. FILE *f;
  18. if ((f=fopen("zborovi.txt","r"))==NULL) {
  19. printf("datotekata zborovi,txt ne moze da bide otvorena\n");
  20. return -1;
  21. }
  22. char c;
  23. char str[100];
  24. int i;
  25. int br=0;
  26. int start,end;
  27. char newstr[100];
  28. fscanf(f,"%c",&c);
  29. while ((fgets(str,100,f))!=NULL) {
  30. int n=strlen(str);
  31. i=0;
  32. while (i<n) {
  33. if (isalnum(str[i])) {
  34. start=i;
  35. while (i<n&&isalnum(str[i])) {
  36. i++;
  37. }
  38. end=i-1;
  39. if (str[start]==c && str[end]==c) {
  40. br++;
  41. strncpy(newstr,str+start,end-start+1);
  42. printf("%s ",newstr);
  43. }
  44. }
  45. else i++;
  46. }
  47. printf("\n");
  48. }
  49. printf("%d",br);
  50. fclose(f);
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement