samir82show

line folder

Nov 16th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #include<stdio.h>
  2. #define LINESIZE 20
  3. int main()
  4. {
  5. int c, cnt, i, lspc;
  6. char charray[LINESIZE];
  7. for(cnt = 0;cnt < LINESIZE; cnt++)
  8. charray[cnt] = 0;
  9. cnt = 0;
  10. lspc = -1;
  11.  
  12. while((c = getchar()) != EOF) {
  13. if(cnt < LINESIZE) {
  14. if(c == '\n') {
  15. for(i = 0;i < cnt;i++)
  16. putchar(charray[i]);
  17. for(i = 0;i < cnt;i++)
  18. charray[i] = 0;
  19. } else {
  20. if(c == ' ')
  21. lspc = cnt;
  22. charray[cnt++] = c;
  23. }
  24.  
  25. } else {
  26. if(c == ' ' || c == '\n') {
  27. for(i = 0;i < cnt;i++)
  28. putchar(charray[i]);
  29. for(i = 0;i < cnt;i++)
  30. charray[i] = 0;
  31. } else {
  32. if(lspc != -1) {
  33. for(i = 0;i < lspc;i++)
  34. putchar(charray[i]);
  35. for(i = 0;i < cnt;i++)
  36. charray[i] = 0;
  37. } else {
  38. for(i = 0;i <= cnt;i++)
  39. putchar(charray[i]);
  40. for(i = 0;i <= cnt;i++)
  41. charray[i] = 0;
  42. putchar('-');
  43. }
  44. }
  45. putchar('\n');
  46. lspc = -1;
  47. cnt = 0;
  48. }
  49. }
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment